There's a ticket in Trac to override the BaseForm in the admin
add/change views of the newforms admin branch. [1] It seems to me that
it would also be useful to override the actual Form object, and to do
so based on information in the request. I think we should add a couple
of methods to ModelAdmin, form_add and form_change, that each take a
request object. The form_change method should also take the object
being edited. Code is probably a little clearer, so:
def form_add(self, request):
fields = flatten_fieldset(self.fielsets_add(request))
return forms.form_for_model(self.model, fields=fields,
formfield_callback=self.formfield_for_dbfield)
def form_change(self, request, obj):
fields = flatten_fieldset(self.fielsets_change(request, obj))
return forms.form_for_model(self.model, fields=fields,
formfield_callback=self.formfield_for_dbfield)
Do we also want to allow a 'form' and a 'base_form' attribute on
ModelAdmin? If we did, the default form_add and form_change methods
could look for form first, and base_form second. It would probably be
best to only allow one or the other though. I feel like both would be
convenient, but if the methods are there, if feels like there would be
3 or more ways to do it. Is the convenience of attributes worth the
extra complexity? My gut reaction is no.
The form_add and form_change methods could also kill off the need for
the special methods proposed by [2]. It requires the user to write
more code, but we can avoid adding yet another special method to
ModelAdmin.
Any thoughts or objections?
Joseph
[1] http://code.djangoproject.com/ticket/4727
[2] http://code.djangoproject.com/ticket/3987
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---