Django Foreign Key Class Not Showing
The goal is to have a dashboard show a list of users in your area. The list of users works and it shows the Username. The only issue is I can't get the users images (ideally just h
Solution 1:
You can get user's images direcly from user object using images_set
attribute.
In your case you can do something like this:
{% for user in users %}
{% with first_image=user.images_set.first %}
{% if first_image %}
<a href="{{ first_image.image.url }}" target="_blank">
<img src="{{ first_image.image.url }}"class="" style="max-width: 300px">
{% endif %}
{% endwith %}
{% endfor %}
Post a Comment for "Django Foreign Key Class Not Showing"