From 2a14a8b5f5067c669836711f5a986a334b9004b3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 18 Nov 2011 16:12:05 +0530 Subject: [PATCH] list_per_page 500 to allow position re-ordering for large list --- urbstudio/static/css/projects.css | 2 -- urbstudio/urb/admin.py | 13 +++++++++++++ urbstudio/urb/models.py | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/urbstudio/static/css/projects.css b/urbstudio/static/css/projects.css index db59884..45b099c 100755 --- a/urbstudio/static/css/projects.css +++ b/urbstudio/static/css/projects.css @@ -22,6 +22,4 @@ border:1px inset #999; overflow-y:auto; } -#slidesContainer -{-webkit-touch-callout: none;} diff --git a/urbstudio/urb/admin.py b/urbstudio/urb/admin.py index bb680b9..1c62227 100755 --- a/urbstudio/urb/admin.py +++ b/urbstudio/urb/admin.py @@ -6,14 +6,27 @@ class ProjectImageInline(admin.TabularInline): model = ProjectImage extra = 20 + class ProjectAdmin(admin.ModelAdmin): + class Media: + js = ( + 'js/jquery-ui-1.8.16.custom.min.js', + 'js/admin_list_reorder.js', + ) + prepopulated_fields = {'slug': ('title',)} inlines = [ProjectImageInline] + list_display = ('__unicode__', 'position',) + list_editable = ('position',) + exclude = ('position',) + list_per_page = 500 + class SliderImageAdmin(admin.ModelAdmin): list_display = ('__unicode__', 'order',) list_editable = ('order',) + admin.site.register(Project, ProjectAdmin) admin.site.register(SliderImage, SliderImageAdmin) admin.site.register(Link) diff --git a/urbstudio/urb/models.py b/urbstudio/urb/models.py index 480cc15..4a4b3e6 100755 --- a/urbstudio/urb/models.py +++ b/urbstudio/urb/models.py @@ -7,6 +7,7 @@ def project_thumb_path(instance, filename): class Project(models.Model): + position = models.IntegerField() title = models.CharField(max_length=255) slug = models.SlugField() thumb_image = models.ImageField(upload_to=project_thumb_path) @@ -17,8 +18,22 @@ class Project(models.Model): # end_date = models.DateField(blank=True) # location = models.CharField(max_length=255, 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(Project, self).save(*args, **kwargs) + class Meta: - ordering = ['-id'] + ordering = ['position'] def get_info(self): return {