How to get the specific field of foreignkey using values function in Django?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to get the specific field of foreignkey using values function in Django?



Suppose Foo, Entry are two Django models, and foo is a foreignkey in Entry.
The Django QuerySet Api says that,If you have a field called foo that is a foreignkey, the default values() call will return a dictionary key called foo_id( https://docs.djangoproject.com/en/dev/ref/models/querysets). My question is how to get the specific field of foreignkey foo by values()? That is, if FIELDS is a field of fool,when I get a dictionary list of Entry, how to show FIELDS in the return dictionary, not the foo_id?




1 Answer
1



You can use double underscores to denote a field of a foreign key:


Entry.objects.values('fool__FIELDS')






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name