Django prefetch_related failing to pass data to template -


i have 2 django models:

class product(models.model):     name = models.charfield(max_length=80, null=true)     is_active = models.booleanfield(default=false, null=false)  class image(models.model):     url = models.charfield(max_length=255, unique=true, null=false)     product = models.foreignkey('product', related_name='images') 

i have specific set of products. each product has multiple images. initial call looks like:

product_list = product_list.filter(is_active=true).prefetch_related('images') 

the product_list gets whittled down depending on filters applied.

when try use product_list within display layer (template), iterate list of products. can access product's fields except images.

{{ product.images.0.id }} ==> empty

{{ product.images }} ==> returns image.none

running code through debugger, can see image sql query being executed, it's none of data passed template. there data there, can verify query running through sql client. 1 know why happening? how access images given product?

i solved issue. prefetched data had accessed like: product.images.all.0.id


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -