There was a typo:

products = Product.objects.all()
for product in products:
    product.image = product.productimages_set.first()


Other than that, it should work. You could try this in the django shell, 
just to verify the reverse name of the relationship.

from your_app.models import *
product=Product.objects.first()
product.productimages_set.first()

And debug from there.

El dimarts, 11 juliol de 2017 16:20:00 UTC+2, Bledi va escriure:
>
> Thanks, but I am getting this error:
>
> 'Product' object has no attribute 'productimages_set'
>
>
>
> On Tuesday, July 11, 2017 at 5:29:15 AM UTC-4, ecas wrote:
>>
>>
>> You can query for the images, and keep the first one for the template 
>> rendering.
>>
>> products = Product.objects.all()
>> for product in products:
>>     products.image = product.productimages_set.first()
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ef17071e-e27e-43ba-a012-729372af518e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to