Wednesday, 15 February 2012

python - django for loop over list -


I have a list made by zip

  List = zip (rating, image, comment)   

All elements are queries that are dynamic I

The image is as follows:

  class image (request): location_id = models.IntegerField () bild = models.ImageField (upload_to = ".", Default = '')   

There may be multiple images

Now I want to show the item on that template and to repeat that list I'm grounded. Say, there are 2 images in one place. My problem is:

  {rate for%, image,% in list} How do I show both pictures of one place here? <{Image.bild.name}} gives me the first image {% endfor%}   

Thanks for the help

location should be a field or property of the class, which gives you relevant ratings / comments / images. You can then pass a list of location on your template.

If the location is a Django model, then the rating / comments / images should be in each ForeignKey in the location Indicates. In that case, Django will create properties on the code / location / which points to that rating / comments / images. Use related_name to choose the name of that property, otherwise the name of Django will be invented.

No comments:

Post a Comment