Override Django Admin URLs for Specific Model?

后端 未结 3 1419
一生所求
一生所求 2021-02-15 20:30

First a little background:

I have an Event model that has various event_types. I want to break one of those event types, \'Film\', into it\'s o

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 21:05

    You could override the queryset-method of your EventModelAdmin and filter the queryset so that Film-Events get excluded.

    Something similar to this:

    class EventAdmin(admin.ModelAdmin):
    
        def queryset(self, request):
            qs = super(EventAdmin, self).queryset(request)
            return qs.exclude(event_type='film')
    

提交回复
热议问题