hi,
the plan is to allow for reodering inlines within the admin-interface
(using drag/drop). before starting to work on patches, I´d like to
discuss some issues ...
features:
1. drag/drop (with jQuery-UI sortables).
2. in case of errors (somewhere within the form), the position of
inline-rows should be preserved. this should work for inlines prepared
for deletion as well. empty inline-rows could be moved to the end of
the formset.
the only decent implementation I´ve come up with (so far) is this one:
1. reorder inlines (based on a sortable-field) with a templatetag. it
currently looks like this:
{% for inline_admin_form in inline_admin_formset|
formsetsort:inline_admin_formset.opts.sortable_field %}
2. sortable_field is an attribute defined with your InlineAdmin. it
should be a positiveintegerfield within your model.
3. when submitting the form, the values of the position-fields are
being reindexed.
about 1: this is necessary in order to preserve the position of inline-
rows in case of errors. reordering the inlines with javascript (on
load) is not an option IMO.
about 2: this could also be achieved with order_with_respect_to, but I
think it´s better to explicitely define the sortable-field.
optinal:
using django-positions (https://github.com/jpwatts/django-positions)
could be optional: with a position-field, the reindexing (on submit)
is not necessary.
I already have well tested version of this implementation. the
templatetag is a simple 10-liner (see blow). the only thing needed is
to add the js for sortables to tabular.html and stacked.html (which is
pretty simple as well).
of course, the actual reordering (drag/drop-js) could be optional.
with adding the formsetsort-filter to django, one could implement the
drag/drop easily with a custom template. here´s the template-filter:
@register.filter
def formsetsort(value, arg):
"""
Takes a list of formset dicts, returns that list sorted by the
sortable field.
"""
sorted_list = []
for item in value:
position = item.form[arg].data
if position and position != "-1":
sorted_list.append((int(position), item))
sorted_list.sort()
sorted_list = [item[1] for item in sorted_list]
for item in value:
position = item.form[arg].data
if not position or position == "-1":
sorted_list.append(item)
return sorted_list
what do you think?
regards,
patrick
--
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.