Pass url argument to ListView queryset

前端 未结 2 1602
星月不相逢
星月不相逢 2020-12-30 02:27

models.py

class Lab(Model):
    acronym = CharField(max_length=10)

class Message(Model):
    lab = ForeignKey(Lab)

2条回答
  •  醉话见心
    2020-12-30 03:07

    You need to write your own view for that and then just override the get_queryset method:

    class CustomListView(ListView):
        def get_queryset(self):
            return Message.objects.filter(lab__acronym=self.kwargs['lab'])
    

    and use CustomListView in urls also.

提交回复
热议问题