views:

235

answers:

2

Let's say I want to use a different template for the add page but not the edit. What would be the best way to accomplish that? I was thinking either subclassing add_view or change_view, or alternatively maybe subclass some InlineModelAdmin method. What's your guys take on this? Thanks.

+1  A: 

A good start might be to look at how it's done in django.contrib.auth.admin.UserAdmin for example:

http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/admin.py

I would say subclassing add_view is the way to go here.

Arnaud
Thanks for the answer but the User Admin doesn't utilize any inlines.
orwellian
A: 

This is a pretty crappy solution but here is how I solved it:

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)
orwellian