jrief / django-admin-sortable2

Generic drag-and-drop ordering for objects in the Django admin interface
https://django-admin-sortable2.readthedocs.io/en/latest/
Other
770 stars 180 forks source link

Question about default value of order field #378

Closed stahlnow closed 1 year ago

stahlnow commented 1 year ago

The documentation states that the order field must be 0 by default. The reorder manage command however starts at 1. Which one is correct / does it matter?

jrief commented 1 year ago

The documentation states:

  • my_order's default value must be 0. The JavaScript which performs the sorting is 1-indexed, so this will not interfere with the order of the items, even if they are already using 0-indexed ordering fields.

so what exactly is your question?

stahlnow commented 1 year ago

My question is: Why does the reorder command starts indexing at 1?

jrief commented 1 year ago

If you use a PositiveIntegerField for ordering, then value 0 can be used to signalize a not yet ordered field. This is because sometime you first save an object and perform the ordering in a second step.

The other reason is, that HTML is 1-indexed. In CSS there are pseudo selectors such as :nth-child(…) and they have to start with 1.

stahlnow commented 1 year ago

I see, thanks for the explanation!