我有一个模型如下:
class Artwork(models.Model):
title = models.CharField(max_length=120)
collection = models.CharField(max_length=120,null=True)
slug = models.SlugField(blank=True, unique=True)
description = models.TextField()
price = models.DecimalField(decimal_places=2, max_digits=20, default=0)
image = models.ImageField(upload_to=upload_image_path, null=True, blank=True)
banner = models.ImageField(upload_to='artworks/banner')
video = models.FileField(upload_to='artworks/video',blank=True,null=True)
category = models.CharField(choices=CATEGORY_CHOICES, max_length=15)
views_count = models.IntegerField(default=150)
featured = models.BooleanField(default=False)
active = models.BooleanField(default=True)
created = models.DateTimeField(default=timezone.now)
和视图如下:
def artwork_list_view(request):
queryset = Artwork.objects.all()
context = {
'objet_list':queryset,
}
return render(request, "artworks/list.html", context)
我在模板中使用查询集如下:
<div style='min-height:80px;'><p >First Collection</p></div>
{% for obj in object_list %}
<div class="workSeriesThumbnailStrip">
{% if obj.image %}
<a href="{{ obj.get_absolute_url }}"><img src="{{ obj.image.url }}" style="float:left;width:67px;height:87px;margin:10px;" ></a>
{% endif %}
</div>
{% endfor %}
</div>
知道我有多个集合,并且想在集合中放置一个 for 循环以在一行中显示每个集合的项目。但由于我是 django 的新手,我不知道如何检索集合列表并将它们传递给模板。请帮我。