Proposal: ordering edit-inlines with order_with_respect_to (admin-interface)

37 views
Skip to first unread message

patrickk

unread,
Oct 22, 2008, 12:06:43 PM10/22/08
to Django developers
IMHO, when using "order_with_respect_to", one should be able to order
the inlines (stacked & tabular).

what´s necessary:
1. can_order should be set to true when using "order_with_respect_to".
e.g., if you currently subclass a formset and use can_order=true, there
´s an error in the admin-interface (key "ORDER" not found).
2. ordered_forms should be available independently from is_valid() -
even if there´s an error somewhere in your form, the ordering should
be retained.

note: this proposal is not about integrating some drag/drop-
functionality within the templates (using javascript). although that
would be nice, it´s just about having the _possibility_ to reorder
stuff.

thanks,
patrick

patrickk

unread,
Oct 24, 2008, 1:58:44 AM10/24/08
to Django developers
if someome points me to the right direction, I might be able to
provide a patch for this issue. yesterday, I tried to sketch the
relations between the different formset-classes, -methods and -
helpers, but (to be honest) I´m a bit lost here.

furthermore, it´be interesting if the dev-team wants this to be solved
or if this behaviour is intentional (for whatever reason).

thanks,
patrick

Jacob Kaplan-Moss

unread,
Oct 28, 2008, 11:31:27 AM10/28/08
to django-d...@googlegroups.com
On Wed, Oct 22, 2008 at 10:06 AM, patrickk <pat...@vonautomatisch.at> wrote:
> IMHO, when using "order_with_respect_to", one should be able to order
> the inlines (stacked & tabular).

Yup, this has been on the todo list for quite some time. We even
discussed it at PyCon a couple years ago as we kicked off
newforms-admin. A few things that I recall from that discussion:

* We decided that we'd like to remove ``order_with_respect_to`` —
particularly the way it adds a magical ``_order`` field — in favor of
an explicit ``OrderingField``.

* This would work with related objects::

class Poll(Model):
...

class Choice(Model):
poll = ForeignKey(Poll, related_name="choices")
order = OrderingField(with_respect_to="poll")

* This would give you an API that provided things like
``poll.choices.in_order()`` and ``poll.choices.set_order()``.

* ``OrderingField``s would also work without a related object::

class Person(Model):
order = OrderingField()

* That'd allow APIs like ``Person.objects.in_order()`` and
``Person.objects.set_order()``.

I can't recall more of this discussion, but perhaps this'll be enough
to get you (or someone) started?

Jacob

patrickk

unread,
Oct 29, 2008, 4:54:54 AM10/29/08
to Django developers
thanks, jacob.
doing the OrderingField doesn´t seem too much or a problem (and I do
like the idea of getting rid of order_with_respect_to).

where I´m really struggeling is the admin-interface:
let´s say I have changed the order of my inline-related forms, I´ve
made an error (e.g. a required field is not given somewhere within the
whole form) and then I click "submit".
of course, the inline-related forms should be displayed in the new
order - but that order is not saved yet. so, I´m not quite sure how
this OrderingField has to be connected with the admin-functionality.
the only solution I can think of right now is reordering the inline-
related forms via javascript onload. but that´s already possible and
doesn´t require an OrderingField.
it gets even more complicated when thinking of empty extra forms,
ordered between forms with an "original". these empty forms should be
removed from the list (in case of an error) from my point of view.

any ideas on how to reorder inline-related forms in case of an error? I
´d definitely prefer a non-javascript-solution ...

thanks,
patrick


On 28 Okt., 16:31, "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages