From 91720183f20e64037d78c59522436ecb555e7ba7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 2 Oct 2012 18:20:07 +0530 Subject: [PATCH] Noteworthy admin drag n drop --- requirements.txt | 2 +- urbstudio/urb/admin.py | 16 +++++++++++++++- urbstudio/urb/models.py | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8cab98c..deb1ccd 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -e svn+http://code.djangoproject.com/svn/django/branches/releases/1.3.X/#egg=django --e bzr+http://code.0xdb.org/python-ox/#egg=python-ox +ox django_extensions South diff --git a/urbstudio/urb/admin.py b/urbstudio/urb/admin.py index ad424e6..616bdcf 100755 --- a/urbstudio/urb/admin.py +++ b/urbstudio/urb/admin.py @@ -22,6 +22,20 @@ class ProjectAdmin(admin.ModelAdmin): list_per_page = 500 +class NoteworthyAdmin(admin.ModelAdmin): + class Media: + js = ( + 'js/jquery-ui-1.8.16.custom.min.js', + 'js/admin_list_reorder.js', + ) + + list_display = ('__unicode__', 'position',) + list_editable = ('position',) + exclude = ('position',) + list_per_page = 500 + + + #class SliderImageAdmin(admin.ModelAdmin): # list_display = ('__unicode__', 'order',) # list_editable = ('order',) @@ -30,4 +44,4 @@ class ProjectAdmin(admin.ModelAdmin): admin.site.register(Project, ProjectAdmin) #admin.site.register(SliderImage, SliderImageAdmin) admin.site.register(Link) -admin.site.register(Noteworthy) +admin.site.register(Noteworthy, NoteworthyAdmin) diff --git a/urbstudio/urb/models.py b/urbstudio/urb/models.py index 4a4b3e6..ffc0926 100755 --- a/urbstudio/urb/models.py +++ b/urbstudio/urb/models.py @@ -93,11 +93,26 @@ class Link(models.Model): class Noteworthy(models.Model): + position = models.IntegerField(null=True) image = models.ImageField(upload_to='noteworthy_imgs/') title = models.CharField(max_length=255) description = models.TextField(blank=True) url = models.URLField(blank=True) + def save(self, *args, **kwargs): + model = self.__class__ + + if self.position is None: + # Append + try: + last = model.objects.order_by('-position')[0] + self.position = last.position + 1 + except IndexError: + # First row + self.position = 0 + + return super(Noteworthy, self).save(*args, **kwargs) + def __unicode__(self): return self.title