1👍
✅
Edit
From https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.select_related, you can try like this:
e = Entry.objects.select_related('blog').filter(...)
return serializers.serialize('json', [x.blog for x in e])
1👍
Thanks to @bento who suggested the following answer, which is available at django serialize foreign key objects:
entries = Entry.objects.select_related('blog').filter(...)
list = []
for row in entries:
list.append({'blog_title':row.blog.title, 'entry_title': row.title})
return json.dumps(list)
- [Answered ]-How to specify an "upload to" path in a Form File Field in Django?
- [Answered ]-Django send mail and sms after 6 hours of user sign up
- [Answered ]-How to to override database settings in a Django TestCase
- [Answered ]-Django 1.10 Delete large cascade querySet
- [Answered ]-Django Rest Framework + JWT
Source:stackexchange.com