Problems specifying fields for admin inline

335 views
Skip to first unread message

jeff

unread,
Feb 26, 2009, 1:51:37 AM2/26/09
to Django users
I'm trying to modify the default Site admin page to include an inline
model. Everything seems to be working fine except that no matter what
I try I can't get it to limit the fields displayed in the inline. When
I go to the site edit page in the admin, it shows the standard site
fields as it should, but it shows every field defined for the inline
model, not just the one I tell it to. The relevant code is below. Any
help would be greatly appreciated.

-----
# admin.py

from django.contrib import admin
from django.contrib.sites.models import Site
from django.contrib.sites.admin import SiteAdmin
from django.forms.models import inlineformset_factory
from lindt.sections.models import TopNav

admin.site.unregister(Site)

class TopNavInline(admin.StackedInline):
model = TopNav
formset = inlineformset_factory(
Site,
TopNav,
fields = ('order',)
)
extra = 0
max_num = 0

class SiteAdminMod(SiteAdmin):
inlines = [TopNavInline]

admin.site.register(Site, SiteAdminMod)

Alex Gaynor

unread,
Feb 26, 2009, 1:58:09 AM2/26/09
to django...@googlegroups.com
Drop the formset = bit and simply provide fields = ['order'] in the InlineModelAdmin definition.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

jeff

unread,
Feb 26, 2009, 2:30:36 AM2/26/09
to Django users
Wow, that's much simpler. They should list that option on the admin
documentation page. Many thanks!

On Feb 25, 10:58 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:

James Bennett

unread,
Feb 26, 2009, 2:45:01 AM2/26/09
to django...@googlegroups.com
On Thu, Feb 26, 2009 at 2:30 AM, jeff <jmsc...@gmail.com> wrote:
> Wow, that's much simpler. They should list that option on the admin
> documentation page. Many thanks!

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-options

"The InlineModelAdmin class is a subclass of ModelAdmin so it inherits
all the same functionality as well as some of its own:"

(in other words, anything that's legal to do on a plain ModelAdmin is
legal to do on an InlineModelAdmin)


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Reply all
Reply to author
Forward
0 new messages