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
774 stars 180 forks source link

Sortable sorting on drag, but not saving #296

Closed bradrice closed 2 years ago

bradrice commented 2 years ago

I can sort using the drag handles in my list. The items sort, but when I reload the page, the items go back into the previous sort order. How does the module save the sorted items?

jrief commented 2 years ago

Are you talking about the list view of a model, or the inlined list view of a model's detail view?

bradrice commented 2 years ago

image

In a list view of a model

from django.contrib import admin
from .models import Artwork, Category
from adminsortable2.admin import SortableAdminMixin

class ArtworkAdmin(SortableAdminMixin, admin.ModelAdmin):
    js = ('js/form.js',)
    list_display = ('title','weightedOrder', 'forSale', 'sold', 'media', 'price')
    readonly_fields = ('imgheight', 'imgwidth')

admin.site.register(Artwork, ArtworkAdmin)

And my model has: weightedOrder = models.IntegerField(default=0, blank=False, null=False)

a screen capture:

https://www.dropbox.com/s/hh3x7jazhpxntfa/simplescreenrecorder-2022-01-02_10.24.07.mp4?dl=0

jrief commented 2 years ago

django-admin-sortable2 saves the order of the items immediately after they have been dragged. If this doesn't work for you, check that weightedOrder has been initialized, ie. all entries must have different values. Use the management command if required. If it still doesn't work, check your browser dev console.

bradrice commented 2 years ago

I had been using weigthedOrder previously and had been typing values in. Perhaps that is the issue. The docs said I could use a previously used field, so I didn’t realize that was a problem to have similar values.

On Sun, Jan 2, 2022 at 1:20 PM Jacob Rief @.***> wrote:

django-admin-sortable2 saves the order of the items immediately after they have been dragged. If this doesn't work for you, check that weightedOrder has been initialized, ie. all entries must have different values. Use the management command if required. If it still doesn't work, check your browser dev console.

— Reply to this email directly, view it on GitHub https://github.com/jrief/django-admin-sortable2/issues/296#issuecomment-1003755418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACCPYDOOCKA646VEBIOUZDUUCJNRANCNFSM5LCZG2OA . You are receiving this because you authored the thread.Message ID: @.***>

-- Brad Rice @.***

jrief commented 2 years ago

please close this issue

bradrice commented 2 years ago

I tried creating a new field for order and use it as the ordering field. It still won't sort and save.

jrief commented 2 years ago

I tried creating a new field for order and use it as the ordering field.

Did you initialize it?

Anyway, you certainly made a configuration error. This library is used by thousands of projects without complains.

bradrice commented 2 years ago

When you say initialize it, you mean migrate it, correct?

On Wed, Jan 5, 2022 at 2:46 AM Jacob Rief @.***> wrote:

I tried creating a new field for order and use it as the ordering field.

Did you initialize it?

Anyway, you certainly made a configuration error. This library is used by thousands of projects without complains.

— Reply to this email directly, view it on GitHub https://github.com/jrief/django-admin-sortable2/issues/296#issuecomment-1005453165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACCPYH2TALXKDQXCVHRTYDUUPZNXANCNFSM5LCZG2OA . You are receiving this because you authored the thread.Message ID: @.***>

-- Brad Rice @.***

jrief commented 2 years ago

Read the docs: https://django-admin-sortable2.readthedocs.io/en/latest/usage.html#initial-data

bradrice commented 2 years ago

Sorry, I didn't get around to closing this, but yes, it was a matter of initializing the data. I got the reorder tool to work on my model and then it started working. Thank you @jrief