如何在查询中过滤,以便结果排除列表中的一个对象? 什么时候 ID = 1 model = AutoShow
视图:
class autoshow_index(ListView):
context_object_name = "numcar"
model = AutoShow
def get_context_data(self, **kwargs):
context = super(autoshow_index, self).get_context_data(**kwargs)
context['bnrlarg'] = BannerLarge.objects.all()[:1]
return context
模板:
{% for autoshow in object_list %}
<h2><a href="/autoshow_page/{{autoshow.slug}}"> {{ autoshow.title }}</a></h2>
{% endfor %}
答案 0 :(得分:2)
将此信息包含在autoshow_index
课程
def get_queryset(self):
return AutoShow.objects.exclude(id=1)