On Tue, Nov 16, 2010 at 6:02 AM, KentH <k...@khauser.net> wrote:
> Hi,
>
> My ticket was closed by Pandres with the comment:
>
> Your path seems to add another way to do something that is already
> easy to do (and it's done all around in the code). It goes against the
> principle of "there should be one obvious way to do it"
>
>
> Great reason -- but the other path is not obvious to me.

Well, the "other path" is the one that is documented -- {% for form in
formset.forms %}.

> I want to display forms from a model formset in an order different
> from creation order. Normally, you would sort the queryset input & the
> output comes in the right order. I am trying to display a sparse "many-
> to-many" relationship table (eg: think user ratings for Beatles
> albums). I want to display the Beatles albums in order irrespective of
> is this use has rated any of the albums (thus the "sparse" nature of
> the relation table).
>
> ModelFormSets *really* want to create forms for existing instances
> before creating "extra" forms. This is fine, but there is no reason a
> formset has to "yield" the forms in creation order.

The order of form creation is significant, because it's tied into the
process of identifying whether entries have been added, removed or
changed.

However, you are correct that once they have been created, there's no
inherent reason that they need to be rendered in the same order. The
creation process will guarantee that they fields have the right form
prefixes; rendering order isn't significant.

I've just reopened the ticket; Although Pandres' comment is correct
(i.e., there is already a way to iterate over forms), I think what
you're proposing makes sense, both in terms of consistency in the API,
and in terms of providing a point at which behavior can be modified.

If you want to move this forward, two things are needed:

 * Tests. It's fine to claim that there are no backwards
incompatibilities, but the way you prove this is true (and that your
patch actually works as intended) is with tests. As fair warning -- in
the next day or so, a big patch is going to land refactoring the forms
regressiontests into unit tests, so I'd hold off for a few days before
you start writing tests for this.

 * Documentation. You're changing the recommended API for formsets,
which means that documentation is required -- including updates to
existing documentation that note both the old and new ways of
iterating.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to