【发布时间】:2015-05-09 18:47:42
【问题描述】:
我有一个 django 应用程序,您想在其中显示跟踪到特定画廊的所有图像,但我收到错误:“GalleryDetailsView1”对象没有属性“画廊”
型号
class Gallery(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
image = ThumbnailerImageField(upload_to='paint/%Y/%m/%d')
class Meta:
verbose_name = "Gallery"
verbose_name_plural = " Galleries"
def __unicode__(self):
return self.title
class Paint(models.Model):
AVAILABLE = "Available"
NOT_AVAILABLE = "Not available"
STATUS_PAINT = (
(AVAILABLE, u"Dostępny"),
(NOT_AVAILABLE, u"Nie dostępny")
)
title = models.CharField(max_length=200)
gallery = models.ForeignKey(Gallery, related_name='paint_set')
paint = ThumbnailerImageField(upload_to='paint/%Y/%m/%d')
price = models.CharField(max_length=50, blank=True, null=True)
status = models.CharField(choices=STATUS_PAINT, default=AVAILABLE, max_length=50)
观看次数
class GalleryList(generic.ListView):
model = Gallery
context_object_name = "list"
template_name = "www/gallery_list.html"
class GalleryDetailsView1(generic.DetailView):
context_object_name = "images1"
template_name = "www/gallery_details1.html"
def get_queryset(self):
return Gallery.objects.get(pk=self.kwargs['pk']).paint_set.all()
模板:gallery_details1
{% extends "base.html" %}
{% load thumbnail %}
{% block content %}
{% for i in images1 %}
{{ i.title }}
<hr>
{% endfor %}
{% endblock %}
{% block content_bottom %}{% endblock content_bottom %}
【问题讨论】:
标签: python django templates views django-queryset