On Wed, 2007-11-07 at 22:26 -0600, Joseph Kocherhans wrote: > form_for_model and form_for_instance seem like complicated and clever > ways to accomplish what basically boils down to a form that has a save > method and can accept a model instance in its constructor method. > > I propose we (or I rather) actually build it that way before 1.0. > > Form declaration: > > class MyForm(ModelForm): > model = MyModel > > #optional > def save(self, commit=True): > # do custom save stuff here if needed > [...]
> ModelForm would be a declarative class that requires, at minimum, a > model attribute. Other attributes would include: > > - formfield_callback (a function that takes a db field and **kwargs > and returns a form field or None) > - fields (a list of field names to include in the form) > - exclude (a list of field names to exclude from the form) I'm mostly +1 on this idea. It would remove my real problem with form_for_*, which is that they can't possibly make everybody happy and so we spend a lot of time discussing, or, worse, adding extra features to them to the point they become very difficult to maintain and still not particularly easy to use for anything other than the trivial case. So, yeah, without having seen the code, I'm pretty much in favour (don't screw it up by writing ugly code now!). > > The biggest problem I see is that this would be entirely backwards > incompatible with the way form_for_model and form_for_instance work > now. (especially the latter) It *may* be possible to change form_for_X > into some sort of hackish wrappers, but it wouldn't be pretty. It's probably possible to write compatibility wrappers as a once-off. I suspect it won't be too much more complex than what we've got now. The current code already calls type() with arguments, so this is going to be similar: constructing a class object dynamically. Regards, Malcolm -- If at first you don't succeed, destroy all evidence that you tried. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---