Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我想为添加页面使用不同的模板,而不是编辑。实现这一目标的最佳方法是什么?我在考虑子类化 add_view 或 change_view,或者子类化一些 InlineModelAdmin 方法。你的人对此怎么看?谢谢。
这是一个非常糟糕的解决方案,但这是我解决它的方法:
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)