Reputation: 657
I'm trying to query only a specific field in Django model. After some searching, I figured out that I need to use only()
. However I need to use filter(authuser=request.user)
as well. How do I make it possible? Thank you.
Upvotes: 0
Views: 346
Reputation: 519
You can chain refinements together, since that returns another QuerySet.
Lets say the model is User, and the field is name.
User.objects.filter(authuser=request.user) \
.only('name')
You can pass other fields to .only()
, they just need to be comma separated.
Upvotes: 1