#8999: ModelAdmin.get_form and get_formset will overwrite self.exclude with a
kwargs exclude
-------------------------------------------+--------------------------------
Reporter: seanl | Owner: jkocherhans
Status: assigned | Milestone:
Component: django.contrib.admin | Version: 1.0
Resolution: | Keywords:
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------------+--------------------------------
Changes (by bkonkle):
* cc: [email protected] (added)
Comment:
I just ran into this bug, myself. If the 'exclude' kwarg is intended to
override self.exclude, then {{{exclude.extend(kwargs.get("exclude",
[]))}}} should not be called. This implies that the kwarg will extend
self.exclude.
My use case here is an ModelAdmin object where I'm overriding get_form to
exclude two fields if this is a change as opposed to a create action. My
ModelAdmin subclass has readonly_fields defined, which by default extend
self.exclude in the ModelAdmin class's get_form method. I'm doing:
{{{
#!python
if obj:
kwargs['exclude'] = ['field', 'other_field']
return super(MySubclass, self).get_form(request, obj,
**kwargs)
}}}
The end result is that the readonly_fields I have defined on my subclass
get presented twice in the rendered admin view, since defaults['exclude']
is overridden by the 'exclude' kwarg.
It's easy to fix, of course, but the existing code in ModelAdmin.get_form
is confusing.
--
Ticket URL: <http://code.djangoproject.com/ticket/8999#comment:8>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.