So, I'm going to pretend you didn't say anything about rearranging
positional arguments because a) it doesn't work, and b) your patch
doesn't do that. So, my response will assume that you are suggesting
that instance become a keyword argument rather than the first
positional argument, and that if 'instance' isn't given, the ModelForm
will create one.

On 12/8/07, James Bennett <[EMAIL PROTECTED]> wrote:

[snip]

>
> Right now I'm
> curious as to why, if it already knows from its Meta class what model
> it's working with, ModelForm *always* needs an instance of the model;

The ModelForm doesn't *always* know what the model is though. You can
build a ModelForm *without* using an inner Meta class. The use case
may be a bit of a stretch, but here it is: Imagine a few models that
have latitude and longitude fields. You could build a ModelForm for
lat/long that would work with any one of these objects since the
ModelForm isn't bound to a particular model until it's instantiated.
The only requirement is that the fields names are the same. Yes, I'm
aware this isn't an argument to *always* require an empty model, you
could get the same effect and only require an empty instance for
ModelForms that haven't already been tied to a particular model.

> it seems that it'd be better for 'instance' to default to None, and
> have ModelForm be smart enough to create its own instance when none is
> supplied.

We can't always do so for the reasons stated above.

> This would also preserve backwards compatibility with the
> general historical trend of "forms that create model instances" --
> neither AddManipulator nor form_for_model have ever required users to
> supply their own empty instance, and ModelForm's requirement of an
> instance in all cases makes generic form-handling code somewhat
> tortuous.

Turning instance into a keyword argument optimizes the syntax for the
add case over the change case (right now it's vice versa). Meh. Code
churn. But, it does have the benefit of making the constructor
signature of Form and ModelForm the same. I can see people tripping up
on the differences... a lot in fact. My original intent with making it
positional was to encourage people to assign defaults to a new model
object before passing it to the form rather than doing the
form.save(commit=False) dance. I knew it was heavy handed, but it
feels even more so now.

> Anyone have strong objections to either of these proposals?

I'm fine with changing the method signature, but I really think you
patch should handle the use case I mentioned before though. It
shouldn't be that difficult.

Joseph

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to