jrief/django-admin-sortable2 — pull request #11 by coredumperror (2014-02-24 23:50:44+00:00)
Title: Added ability to drag/drop new entries in tabular inline sets.

Hi again! Right when I was about to finish up my addition of djgano-admin-sortable2 to my project, I discovered that adding a new inline entry was always putting the entry at the beginning of the list, instead of the end. I knew from having looked at the code in djgano-admin-sortable2's admin.py that it was supposed to be putting new entries at the end, so I dug in and tried to find out why this was happening.

In turns out that since I use South, and added the sort field to my model after it was originally migrated, South forced me to specify a default value for my sort field (because it's NOT NULL). I specified 0, and that meant that `CustomInlineFormSet.save_new()`'s method of determining if it should use `max_order` was failing, since it apparently assumes that the value will be NULL, rather than 0. This is problematic both because of the South issue, and because the existing README for this project states that you should use `null=False` in the definition for the sort order field.

So I changed `CustomInlineFormSet.save_new()`, and also tweaked the javascript as mentioned below in my original commit message. I also updated the documentation to match the change in `save_new()`, and made some grammar and spelling fixes while I was at it.

I haven't tested this with anything but inline entries, though, so there may be some issues with the `default=0` bit in other places.

---- ORIGINAL COMMIT MESSAGE ----

In order to implement this, I needed to make two changes, one of
which is fairly significant.

1) The javascript no longer limits the drag mechanism to	's with
the "has_original" class.
2) The CustomInlineFormSet.save_new() function now checks default_sort_order
to see whether it's 0, intead of checking its type. This necessitated a change
to the documentation, stating that "default=0" must be added to the sort field.

The default has to be zero for two reasons:

1) It simplifies that check in CustomInlineFormSet.save_new(). A default of 0 is
compatible with the javascript, since it uses 1-indexed sorting.
2) Users of the newest South versions are forced to provide a default value when
they add a new sort field to their model.

Ultimately, this change allows us to know for certain what the default value will
be for a new inline entry which has not yet been dragged, allowing the max_order
algorithm to work properly in all cases.