Comments (13)
Hi,
this issue happens when all your data have same my_order value (my_order=0).
http://django-admin-sortable2.readthedocs.org/en/latest/usage.html#initial-data helps me.
from django-admin-sortable2.
ListView or Stacked/Tabluar-Inlines?
from django-admin-sortable2.
ListView --> I looked into the console, it send the POST request and get a response without error but not updated.
from django-admin-sortable2.
Confirmed.
In the sortable ListView, drag and drop produce POST requests like below:
/admin/mall/homepageitem/adminsortable_update/
endorder=0&o=1&startorder=0
And get a "[]" response. Nothing changes in the database though.
from django-admin-sortable2.
Can you please try the supplied example. I just retested the current version and everything works fine.
The POST request should btw. return a JSON object, rather than a list.
from django-admin-sortable2.
@bn0ir Yeah that is my current situation!
I'll try to confirm it by setting order to different values and trying again.
from django-admin-sortable2.
@jrief I think I have located the problem:
The example works all right. However if I changed all "my_order" to 0 in the data fixture, the problem described in this issue happens. Drag and drop will produce a post request, but the parameter only contains "startorder" and no "endorder", and the response is "[]".
Another related problem is that if I write a model similar with the example, it will not work in fact! Since the default value for "my_order" is 0 and there is no auto increment property for that field, the resulting data will have 0s in all rows, making the django-sortable-admin2 not working.
from django-admin-sortable2.
However if I changed all "my_order" to 0 in the data fixture, the problem described in this issue happens.
so, you propose to sanitize bogus initial data.
Since I discourage to add a unique key on the order field, yes, this makes somehow sense. On the other side, it adds quite a lot of additional computation and I don't know, if this is worthwhile.
What about adding a management command to sanitize the data?
from django-admin-sortable2.
@jrief First of all: should the plugin only work with unique (or non-all-zero) orders? If yes, you should make that clear in the document and suggest users to do use an AutoField or deal with the default value for order field themselves. A manage command might be handy I think.
If not, it should be considered as a bug and fix is needed.
from django-admin-sortable2.
In theory, a unique field would be the best choice. However this only works with Postgres, as noted in the docs. AutoField, hmmm, IMO, doesn't fit here.
A manage command might be the best solution.
Anyway, if the values are set once, this module should work. So this bug is not too serious.
from django-admin-sortable2.
Oh yeah, only one AutoField is allowed. :)
Well, I'm a little confused.
How does adding a manage command solve the problem? If the model field has a default 0 without some sort of special auto process, this plugin will always break I think. The user should either run the manage command now and then, or some kind of "advanced default value" is needed.
Both approaches need to be documented.
from django-admin-sortable2.
Please test with the latest version from GitHub.
I just added a management command which presets the ordering.
from django-admin-sortable2.
Agree with @Hexcles, running the management command fixes the problem but it's not optimal.
@jrief would you consider a PR that runs this https://github.com/jrief/django-admin-sortable2/blob/master/adminsortable2/management/commands/reorder.py#L21 when all your records are equal to the field default value?
from django-admin-sortable2.
Related Issues (20)
- Signal for Model is not Triggered when Item is Dragged HOT 3
- missing template(s) for Django 4.2 HOT 3
- No handle
- Newer order values voilates the field rule of PositiveIntegerField HOT 11
- Incorrect code example in documentation (Sec. "Many-to-Many Relations")
- Don't install testapp and its child modules HOT 8
- adminsortable2 - TemplateNotFound HOT 2
- Make *only* inlines sortable and not the base model admin?!? HOT 2
- 2.1.9 version inconsistent?
- RecursionError: maximum recursion depth exceeded while calling a Python object HOT 1
- Unable to see sort column (no pads) v2.1.9 HOT 3
- Admin UI does not get added HOT 1
- Question about default value of order field HOT 4
- small typo + latest docs are not deployed? HOT 2
- What about supporting Python 3.11 and 3.12? HOT 2
- Why not adapt for django 3.2? HOT 6
- Sorting does not work for StackedInline if widget of the field has <table> HOT 2
- I am trying to add a custom formset and extend it with django.forms.models.Baseinlineformset which is not working as it is raising the error "BaseFormSet.__init__() got an unexpected keyword argument 'default_order_direction'
- Is SortableStackedInline compatible with django-polymorphic?
- Support for Django 5 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-admin-sortable2.