I have two models: the first Property model and the second model Property Image:
Class Property(models.model):
title = models.CharField()
Class PropertyImage(models.model):
property = modelos.Foreignkey(Property, related_name='images')
imagen = models.ImageField()
PropertyImage is where the images of the properties are stored and is related to the first model with a foreign key.
I know that to get the url of the first image of a property in a query would do something like this:
p1 = Property.objects.first() # la primera propiedad
p1.images.first() # la primera imagen de la propiedad 1
My question is if the template sent a query where all the properties are (or filtered according to the case) as it would within the template to show only the url of the first image for each property?
I tried to use the first function inside the template but it marks me syntax error.