Noteworthy admin drag n drop
This commit is contained in:
parent
e34d6fb61f
commit
91720183f2
|
@ -1,4 +1,4 @@
|
||||||
-e svn+http://code.djangoproject.com/svn/django/branches/releases/1.3.X/#egg=django
|
-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
|
django_extensions
|
||||||
South
|
South
|
||||||
|
|
|
@ -22,6 +22,20 @@ class ProjectAdmin(admin.ModelAdmin):
|
||||||
list_per_page = 500
|
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):
|
#class SliderImageAdmin(admin.ModelAdmin):
|
||||||
# list_display = ('__unicode__', 'order',)
|
# list_display = ('__unicode__', 'order',)
|
||||||
# list_editable = ('order',)
|
# list_editable = ('order',)
|
||||||
|
@ -30,4 +44,4 @@ class ProjectAdmin(admin.ModelAdmin):
|
||||||
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)
|
||||||
admin.site.register(Noteworthy)
|
admin.site.register(Noteworthy, NoteworthyAdmin)
|
||||||
|
|
|
@ -93,11 +93,26 @@ class Link(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Noteworthy(models.Model):
|
class Noteworthy(models.Model):
|
||||||
|
position = models.IntegerField(null=True)
|
||||||
image = models.ImageField(upload_to='noteworthy_imgs/')
|
image = models.ImageField(upload_to='noteworthy_imgs/')
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
url = models.URLField(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):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user