Modified classmethod queries that determine if a Model is sortable to only retieve one record and not use count.

Fixed jQueryUI highlight method call in success handler of ajax function when dragging stops.
Fixed missing script resource for jquery.effects.core.js
master
Brandon Taylor 2011-11-16 00:48:14 -06:00 committed by Brandon Taylor
parent 638f26df27
commit 8365043e0e
77 changed files with 10917 additions and 10892 deletions

1
.gitignore vendored 100644 → 100755
View File

@ -4,3 +4,4 @@ django_admin_sortable.egg-info
.pydevproject
*.pyc
*.pyo
.idea

0
AUTHORS 100644 → 100755
View File

0
COPYRIGHT 100644 → 100755
View File

0
MANIFEST.in 100644 → 100755
View File

0
README 100644 → 100755
View File

0
adminsortable/__init__.py 100644 → 100755
View File

0
adminsortable/admin.py 100644 → 100755
View File

View File

View File

View File

26
adminsortable/models.py 100644 → 100755
View File

@ -3,15 +3,30 @@ from django.db import models
class Sortable(models.Model):
"""
Unfortunately, Django doesn't support using more than one AutoField in a model
or this class could be simplified.
`is_sortable` determines whether or not the Model is sortable by determining
if the last value of `order` is greater than the default of 1, which should be
present if there is only one object.
`model_type_id` returns the ContentType.id for the Model that inherits Sortable
`save` the override of save increments the last/highest value of order by 1
"""
order = models.PositiveIntegerField(editable=False, default=1, db_index=True)
class Meta:
abstract = True
ordering = ['order', 'id']
ordering = ['order']
@classmethod
def is_sortable(cls):
return True if cls.objects.count() > 1 else False
try:
return True if cls.objects.order_by('-order')[:1][0].order > 1 else False
except IndexError:
return False
@classmethod
def model_type_id(cls):
@ -19,5 +34,10 @@ class Sortable(models.Model):
def save(self, *args, **kwargs):
if not self.id:
self.order = self.__class__.objects.count() + 1
try:
#increment the order field by adding one to the last value of order
self.order = self.__class__.objects.order_by('-order')[:1][0].order + 1
except IndexError:
#order defaults to 1
pass
super(Sortable, self).save(*args, **kwargs)

View File

@ -22,7 +22,7 @@ jQuery(function($){
data: { indexes : indexes.join(',') },
success: function()
{
ui.effect('highlight');
ui.item.effect('highlight', {}, 1000);
}
});
}

View File

View File

View File

View File

View File

View File

View File

View File

View File

0
sample_project/README 100644 → 100755
View File

0
sample_project/__init__.py 100644 → 100755
View File

BIN
sample_project/adminsortable.sqlite 100644 → 100755

Binary file not shown.

0
sample_project/app/__init__.py 100644 → 100755
View File

0
sample_project/app/admin.py 100644 → 100755
View File

View File

View File

View File

View File

0
sample_project/app/models.py 100644 → 100755
View File

2
sample_project/app/tests.py 100644 → 100755
View File

@ -34,7 +34,7 @@ class SortableTestCase(TestCase):
self.user.save()
def create_category(self, title='Category 1'):
category = Category.objects.create(title=title)
category, _ = Category.objects.get_or_create(title=title)
return category
def test_new_user_is_authenticated(self):

View File

View File

0
sample_project/appmedia/api.py 100644 → 100755
View File

View File

View File

0
sample_project/appmedia/models.py 100644 → 100755
View File

0
sample_project/appmedia/urls.py 100644 → 100755
View File

0
sample_project/appmedia/views.py 100644 → 100755
View File

0
sample_project/manage.py 100644 → 100755
View File

1
sample_project/settings.py 100644 → 100755
View File

@ -102,6 +102,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (

View File

@ -14,7 +14,10 @@ jQuery(function($){
$.ajax({
url: ui.item.find('a.admin_sorting_url').attr('href'),
type: 'POST',
data: { indexes: indexes.join(',') }
data: { indexes: indexes.join(',') },
success: function(){
ui.item.effect('highlight', {}, 1000);
}
});
}
});

View File

View File

View File

View File

View File

View File

View File

View File

0
sample_project/urls.py 100644 → 100755
View File

0
setup.py 100644 → 100755
View File