Is there Django List View model sort?

前端 未结 2 1240
一整个雨季
一整个雨季 2021-02-02 10:41

I\'m using ListView in my Class Based Views and I was wondering if there was a way to display the model object set on the template by sorting it. This is what I hav

2条回答
  •  醉话见心
    2021-02-02 11:02

    Why don't you override the get_queryset method like this:

    class Reviews(ListView):
        model = ProductReview
        paginate_by = 50
        template_name = 'review_system/reviews.html'
    
        def get_queryset(self):
            return YourModel.objects.order_by('model_field_here')
    

提交回复
热议问题