Increasing the usefulness of ModelAdmin.get_formsets

42 views
Skip to first unread message

Florian Apolloner

unread,
Oct 24, 2010, 5:01:55 PM10/24/10
to Django developers
Hi,

in one of my projects I would like to alter the inlines in the admin
on a per request basis. So I though I could use get_formsets to drop
unneeded inlines; this isn't the case :( get_formsets has to return
the same inlines in the correct order (eg
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py#L789
requires this). Maybe we could add a method like
get_formsets_with_inlines (better name anyone) which (by default)
would just return zip(self.get_formsets(request),
self.inline_instances). This would increase the usefulness of
get_formsets quite a bit imo. Any thoughts?

Cheers, Florian Apolloner

Russell Keith-Magee

unread,
Oct 25, 2010, 9:43:58 AM10/25/10
to django-d...@googlegroups.com

Sounds like a reasonable idea in general. However,
get_formsets_with_inlines strikes me as exposing a little too much of
the internal implementation.

Having a quick look at the code, it strikes me that the actual use
case here is 'get_formset_instances()' -- the prefixing and formset
instantiation logic is essentially shared between the three places
that get_formsets() are used, and would provide the entry point that
you need to eliminate formsets on a per-request basis. I'd be a lot
more comfortable with an API at than one that provides 'zip some stuff
together' level functionality.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages