I would like to ask, if it is possible to pick existing random object id in template.
Here are my models.py:
class ImageInGallery(models.Model):
image = models.ImageField(upload_to='media/photos/')
views.py;
class GalleryListView(ListView):
model = ImageInGallery
context_object_name = 'images'
def get_queryset(self):
return ImageInGallery.objects.all().order_by('-id')
In the template I would like to to something like this:
{% for picture in images %}
{% if picture.id == X %}
<img src="{{ picture.image.url }}">
{% endif %}
{% endfor %}
Where 'X' is the existing random object id of the image model. Is there any way how to do it? Or is there any other better way? Thank you.