On 9/11/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Mon, 2007-09-10 at 18:25 -0500, Joseph Kocherhans wrote: > > 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. > > I agree, for much the same reason: pick one way that looks flexible > enough. The two methods look reasonable. > > I'm not sure why you want both "form" *and* "base_form" in your > attribute approach, but if they're both required (plus maybe add and > change are different attributes?) I think it's another good argument for > the method-based approach. Too many attributes starting to spring up to > handle all possibilities when all you really need at the end of the day > is a form class.
Hi, it just seem to me that adding just the methods will complicate things in the common case - you just want to specify some additional validation and/or add some custom fields. IMHO it is sufficient to just supply your base class, you shouldn't have to bother instantiating it as well. so I am +1 on adding base_form and the methods for people who know what they are doing > > Regards, > Malcolm > > -- > Despite the cost of living, have you noticed how popular it remains? > http://www.pointy-stick.com/blog/ > > > > > -- Honza Kr�l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
