如何过滤对象以排除id

时间:2013-03-02 19:51:14

标签: python django

如何在查询中过滤,以便结果排除列表中的一个对象? 什么时候 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 %}  

1 个答案:

答案 0 :(得分:2)

将此信息包含在autoshow_index课程

def get_queryset(self):
    return AutoShow.objects.exclude(id=1)