【发布时间】:2020-05-15 20:50:14
【问题描述】:
我正在对列表和详细信息使用通用视图,在索引页面上我得到了我的列表但没有得到我的类别列表,但我得到了另一个模板上的类别列表。 我想在索引页面上列出类别,然后单击该类别,图像转到按该特定类别过滤的列表。 我希望你能理解我的问题 .下面是品牌索引和类别模型的视图
class BrandsIndexView(generic.ListView):
template_name = "brands/index.html"
context_object_name = "latest_brands_list"
def get_queryset(self):
return Brands.objects.filter(created_on__lte=timezone.now()).order_by('-created_on')[:10]
model for category
class Category(models.Model):
category_name = models.CharField(null=False,max_length=200)
category_slug = models.SlugField(
max_length=200, db_index=True, unique=True)
category_image = models.FileField(upload_to="brand_cat_images",null=True,blank=True,validators=[file_ext])
class Brands(models.Model):
brand_name = models.CharField(max_length=200 , null=False,help_text="Enter Brand Name")
brand_slug = models.SlugField(max_length=200 , unique=True)
brand_logo = models.ImageField(null=False, blank=False, upload_to="brand_logo")
brand_description = models.TextField(max_length=250 ,null=True,blank=True)
brand_category = models.ForeignKey(Category,on_delete=models.CASCADE ,default="None",related_name="category")
【问题讨论】:
-
提供您正在编写的代码,例如模型和视图,以供我们理解。
-
再次检查问题我添加了代码
-
你的品牌型号在哪里?
-
添加到代码中
标签: django django-views django-templates