Display images in template using ManyToMany
MODEL:
class PropertyGallery(models.Model):
link = models.ImageField(upload_to="gallery/props/")
class Property(models.Model):
name = models.CharField(max_length=200)
gallery=models.ManyToManyField(PropertyGallery)
----------------------------------------------------------------------------------
TEMPLATE:
Name: {{p.name}} <br />
{% for a in p.gallery.all %}
<img src="{{ ??????? }}" alt="" /> <--- HERE IM LOST
{% endfor %}
----------------------------------------------------------------------------------
VIEW:
def detail(request, object_id):
p = get_object_or_404(Property, pk=object_id)
return render_to_response('website/detail.html', {'p': p})
Iteration is working, but whatever I'm trying , always <img src="">
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home