On 4/29/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
> Two suggestions about the newforms API:

I'm late to the party on this one, but here are some thoughts --

> 1) Is there room for a 'fields' argument on form_for_instance and
> form_for_model - a list of field names that you want included on the
> form (defaulting to None, meaning the full list), so that it is simple
> to create a form with a subset of a model's full field list?
>
> I realize that you can subclass the form class returned by the
> form_for_ methods and delete the fields you don't want, but 'form from
> field subset' seems like a fairly common use case that can be very
> easily accommodated.

This gets a +1 from me. It's a clearly useful feature.

> 2) I realize that there are historical (i.e.,
> manipulator/pre-magic-removal related) reasons why reverse ForeignKey
> and M2M relations are not contained on forms, but is there any reason
> that newforms should continue the tradition?
>
> We probably don't want to include reverse fields on forms by default
> (if only for backwards compatibility), but providing an optional
> argument (say, reverse_fields=(...), containing a list of reverse
> descriptor names) on form_for_model and form_for_instance would allow
> users to easily include reverse relations on a form.

This one, I'm not so crazy about. I tend to agree with this passage
from the newforms documentation:

"""
When should you use form_for_model() and form_for_instance()?

The form_for_model() and form_for_instance() functions are meant to be
shortcuts for the common case. If you want to create a form whose
fields map to more than one model, or a form that contains fields that
aren't on a model, you shouldn't use these shortcuts. Creating a Form
class the "long" way isn't that difficult, after all.
"""

OK, I'll come clean: I agree with that paragraph because I wrote it. :-)

Still, I think the concept of reverse_fields is too messy of an
abstraction to be useful. There comes a point where it's not worth
inventing frameworks on top of frameworks, and I think we're hitting a
sweet spot pretty well right now, with the current form_for_model()
and form_for_instance() implementations. (With the new "fields"
parameter, it'll get just a bit closer to the sweet spot.) Supporting
reverse relationships, in my mind, makes that sweet spot a bit more
sour.

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

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

Reply via email to