list_per_page 500 to allow position re-ordering for large list

This commit is contained in:
Sanj 2011-11-18 16:12:05 +05:30
parent a2fec744ec
commit 2a14a8b5f5
3 changed files with 29 additions and 3 deletions

View File

@ -22,6 +22,4 @@ border:1px inset #999;
overflow-y:auto; overflow-y:auto;
} }
#slidesContainer
{-webkit-touch-callout: none;}

View File

@ -6,14 +6,27 @@ class ProjectImageInline(admin.TabularInline):
model = ProjectImage model = ProjectImage
extra = 20 extra = 20
class ProjectAdmin(admin.ModelAdmin): 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',)} prepopulated_fields = {'slug': ('title',)}
inlines = [ProjectImageInline] inlines = [ProjectImageInline]
list_display = ('__unicode__', 'position',)
list_editable = ('position',)
exclude = ('position',)
list_per_page = 500
class SliderImageAdmin(admin.ModelAdmin): class SliderImageAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'order',) list_display = ('__unicode__', 'order',)
list_editable = ('order',) list_editable = ('order',)
admin.site.register(Project, ProjectAdmin) admin.site.register(Project, ProjectAdmin)
admin.site.register(SliderImage, SliderImageAdmin) admin.site.register(SliderImage, SliderImageAdmin)
admin.site.register(Link) admin.site.register(Link)

View File

@ -7,6 +7,7 @@ def project_thumb_path(instance, filename):
class Project(models.Model): class Project(models.Model):
position = models.IntegerField()
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
slug = models.SlugField() slug = models.SlugField()
thumb_image = models.ImageField(upload_to=project_thumb_path) thumb_image = models.ImageField(upload_to=project_thumb_path)
@ -17,8 +18,22 @@ class Project(models.Model):
# end_date = models.DateField(blank=True) # end_date = models.DateField(blank=True)
# location = models.CharField(max_length=255, 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: class Meta:
ordering = ['-id'] ordering = ['position']
def get_info(self): def get_info(self):
return { return {