#12755: Proposal: Add a method to ModelAdmin to return the form instance
----------------------------------+-----------------------------------------
Reporter: igors | Owner: nobody
Status: new | Milestone: 1.2
Component: django.contrib.admin | Version: 1.2-alpha
Keywords: | Stage: Unreviewed
Has_patch: 1 |
----------------------------------+-----------------------------------------
Sometimes we need dynamic fields in a form, depending on the logged in
user or something else. Currently the !ModelAdmin class has a
{{{get_form()}}} method, that returns a form class to be used in admin.
But it would be nice to customize the form instantiation when we are
building dynamic forms.
I've attached a patch that adds a {{{get_form_instance()}}} method to
!ModelAdmin, and it receives the request object. This way we can pass
extra parameters to our dynamic form based on some request attributes. For
example:
{{{
def get_form_instance(self, request, form_class, **kwargs):
return form_classe(user=request.user, **kwargs)
}}}
I don't think it breaks backwards compatibility and it's not a new
feature, so probably could be added to 1.2.
--
Ticket URL: <http://code.djangoproject.com/ticket/12755>
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.