开发者

Can I filter instances shown in admin changelist?

开发者 https://www.devze.com 2023-01-24 15:43 出处:网络
I have a model Child inheriting from a model Parent. In the Parent admin I\'ve got Parent and Child instances, while I would like to have only Parent instances (Child instances are managed in Child ad

I have a model Child inheriting from a model Parent. In the Parent admin I've got Parent and Child instances, while I would like to have only Parent instances (Child instances are managed in Child admin).

How can I do that?

than开发者_C百科ks

jul


Override the queryset method in your ModelAdmin subclass to only return the objects you need.

class MyParentAdmin(admin.ModelAdmin):

     def queryset(self, request):
         return Parent.objects.filter(whatever_your_criteria_is=True)
0

精彩评论

暂无评论...
验证码 换一张
取 消