3👍
✅
From what I can see, I think you’ve got a small syntax error:
{% photo.image %}
should instead be:
{{ photo.image }}
The {% %}
notation is used for django template tags. Variables, on the other hand, are expressed with the {{ }}
notation.
To make it dynamic, you can take advantage of the fact that your Photo
model has a foreign key to Recipe
. This means that there will be a reverse relation from the Recipe
instance you’ve loaded using the slug back to the set of photos:
def details(request, slug='0'):
p = get_object_or_404(Recipe, slug=slug)
photos = p.photo_set.all()
Hopefully that will work for you. Glad to see you’re enjoying working with Django!
Source:stackexchange.com