I have installed Django Admin Sortable 2 in to my Django project. I can see the drag and drop order system in the admin but when I move around some objects the order doesn't get saved. I cannot see any error in my terminal log either when moving objects around.
Here is my Model and Admin python files. Do I need to do anything extra to get the order to save?
Model.py
class QuickLink(models.Model):
title = models.CharField(max_length=20)
image = models.FileField(null=True, blank=False,upload_to='media/quick_links')
link = models.CharField(max_length=200)
order = models.PositiveIntegerField(default=0, blank=False, null=False)
def __str__(self):
return self.title
class Meta(object):
ordering = ['order']
Admin.py
from django.contrib import admin
from adminsortable2.admin import SortableAdminMixin
from .models import QuickLink
@admin.register(QuickLink)
class QuickLinksAdmin(SortableAdminMixin, admin.ModelAdmin):
pass
My versions are as follows:
Django 2.0.4
Python 3.6.1
Django Admin Sortable 2 0.6.19
Try running management command:
./manage.py reorder <app.model>
The reason I was having problems re-ordering the objects was I had already created the objects when then adding the Sortable functionality.
When setting a default for this as 0 it would set them all for 0. By going back and either recreating the objects or editing the field in the DB to the correct order I was able to fix this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With