Skip to content
Advertisement

How to serialize first photo in album? Django

How to serialize first photo in album if photo connected by using FK with model Gallery. I need first photo for gallery cover in galley list. My models:

JavaScript

Anyone have any ideas? May be I need suchlike request Gallery.objects.get(id=id).photos.first() but i not sure is it correct.

Advertisement

Answer

get returns only one object. filter returns multiple objects. You can access the ForeignKey fields with __.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement