Reputation: 3467
I have a model with some fields, one of them is a FK. I would like to use
MyModel.objects.all().defer("pk").values()
and to add a field of my FK (myfk__name) without writing all model fields + 1 in the values.
I also would like to avoid doing another query after this one to add it manually.
Is it possible?
Upvotes: 2
Views: 2531
Reputation: 20672
use annotate
:
MyModel.objects.all().defer('pk').values().annotate(name=F('myfk__name'))
Upvotes: 3