0

Django:如何动态删除内联?

4

1 回答 1

0

由于某种原因,对对象没有权限的用户仍然可以通过内联访问它。以下是动态删除它们的方法:

class FooAdmin(admin.ModelAdmin):
    inlines = ['SomeInline']
    ...
    def change_view(self, request, object_id, extra_context=None):
        def delete_inlines(inlines):
            for index, inline in reversed(list(enumerate(self.inlines))):
                if inline.__name__ in inlines:
                   del self.inlines[index]
                   del self.inline_instances[index]
        delete_inlines(['SomeInline' ])
        return super(FooAdmin, self).change_view(request, object_id, extra_context=None)
于 2009-09-25T13:47:12.050 回答