On Tue, 2007-03-27 at 11:18 -0700, Ben Stahl wrote:
> Aren't you duplicating information with the newforms, violating the
> DRY principle? What I mean is, aren't we separately creating most or
> all of the same fields for a form as for the model whose data will be
> bound to the form? Why can't a form be instantiated automatically when
> passed a model (maybe with flags for which fields are enabled)? Or
> better yet, bind the form to a model (or model instance), which would
> at all times keep the form fields in sync with the model. You could
> have a parameter for each model field like form=True or whatever if
> that field should be included in a form.
> 
> Maybe I'm not correctly understanding the relationships here though,
> or missing something. Sorry if that's the case, I am new at Django,
> but so far I love it.

Along with the other answers you've received about using
form_for_instance and form_for_model, I'd like to point another piece of
design logic behind newforms (and even oldforms). This is purely
informational and maybe you already realise it:

It's not always the case that a form consists of data for only one
model. In my own experience, the forms I build collect data that is
ultimately split between multiple models and/or the form fields are
munged prior to being insert into a model -- for example, a
comma-separated list of strings becomes multiple tag instances in the
database.

This sort of usage isn't something that I see discussed on this list a
lot (the splitting tags is, but data -> multiple forms isn't), which
makes me think that by the time you need that, form processing isn't
that hard, or it isn't that common (I suspect the former). Tying form
creation any more tightly to models that via the utility methods already
provided would make the more generic form usage style a bit harder.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to