0

假设我想为添加页面使用不同的模板,而不是编辑。实现这一目标的最佳方法是什么?我在考虑子类化 add_view 或 change_view,或者子类化一些 InlineModelAdmin 方法。你的人对此怎么看?谢谢。

4

1 回答 1

1

这是一个非常糟糕的解决方案,但这是我解决它的方法:

class FooInline(admin.TabularInline):
    model = Foo

    def get_fieldsets(self, request, obj=None): 
       url = request.get_full_path()
       if '/add/' not in url:
           self.template = 'listing.html'
       return super(FooInline, self).get_fieldsets( request, obj)
于 2009-08-25T23:19:03.023 回答