Making inlines conditional in the Django admin

后端 未结 8 2329
长发绾君心
长发绾君心 2021-02-07 21:45

I have a model that I want staff to be able to edit up to the date for the event. Like this:

class ThingAdmin(admin.ModelAdmin):
    model = Thing

    if obj.da         


        
8条回答
  •  一生所求
    2021-02-07 22:23

    In recent version of Django, you'll need to override ModelAdmin.get_formsets. e.g.

    class MyAdmin(admin.ModelAdmin):
    
        def get_formsets(self, request, obj=None):
            if obj:
                for _ in super(MyAdmin, self).get_formsets(request, obj):
                    yield _
            else:
                for inline in self.get_specific_inlines(request):
                    yield inline.get_formset(request, obj)
    

提交回复
热议问题