Giter Club home page Giter Club logo

Comments (13)

bn0ir avatar bn0ir commented on May 29, 2024 1

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.

jrief avatar jrief commented on May 29, 2024

ListView or Stacked/Tabluar-Inlines?

from django-admin-sortable2.

sachitad avatar sachitad commented on May 29, 2024

ListView --> I looked into the console, it send the POST request and get a response without error but not updated.

from django-admin-sortable2.

Hexcles avatar Hexcles commented on May 29, 2024

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.

jrief avatar jrief commented on May 29, 2024

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.

Hexcles avatar Hexcles commented on May 29, 2024

@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.

Hexcles avatar Hexcles commented on May 29, 2024

@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.

jrief avatar jrief commented on May 29, 2024

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.

Hexcles avatar Hexcles commented on May 29, 2024

@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.

jrief avatar jrief commented on May 29, 2024

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.

Hexcles avatar Hexcles commented on May 29, 2024

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.

jrief avatar jrief commented on May 29, 2024

Please test with the latest version from GitHub.
I just added a management command which presets the ordering.

from django-admin-sortable2.

leotsem avatar leotsem commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.