[Django]-Django models ForeignKey return IDs

6👍

✅

You can, by referring to the related field with the __ prefix. The only downside is that you have to list all the other fields as well:

trendingidea.objects.values('readbyadmin',
                            'id',
                            'idea',
                            'submittedon',
                            'support',
                            'readbyadmin',
                            'feasibilitycheck',
                            'submittedby__name',
                            'assignedto__name')

Note that your dictionary will have submittedby__name and assignedto__name keys.

Leave a comment