Update sample_project for easy testing sortable and nonsortable inlines

master
Venelin Stoykov 2014-11-18 17:04:58 +02:00
parent cfcf6b1a46
commit cbce6debb4
3 changed files with 35 additions and 2 deletions

View File

@ -6,7 +6,7 @@ from adminsortable.admin import (SortableAdmin, SortableTabularInline,
from adminsortable.utils import get_is_sortable
from app.models import (Category, Widget, Project, Credit, Note, GenericNote,
Component, Person, NonSortableCategory, SortableCategoryWidget,
SortableNonInlineCategory)
SortableNonInlineCategory, NonSortableCredit, NonSortableNote)
admin.site.register(Category, SortableAdmin)
@ -56,8 +56,21 @@ class GenericNoteInline(SortableGenericStackedInline):
extra = 0
class NonSortableCreditInline(admin.TabularInline):
model = NonSortableCredit
extra = 1
class NonSortableNoteInline(admin.StackedInline):
model = NonSortableNote
extra = 0
class ProjectAdmin(SortableAdmin):
inlines = [CreditInline, NoteInline, GenericNoteInline]
inlines = [
CreditInline, NoteInline, GenericNoteInline,
NonSortableCreditInline, NonSortableNoteInline
]
list_display = ['__unicode__', 'category']
admin.site.register(Project, ProjectAdmin)

View File

@ -71,6 +71,25 @@ class Note(Sortable):
return self.text
# Registered as a tabular inline on `Project` which can't be sorted
class NonSortableCredit(models.Model):
project = models.ForeignKey(Project)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
def __unicode__(self):
return '{0} {1}'.format(self.first_name, self.last_name)
# Registered as a stacked inline on `Project` which can't be sorted
class NonSortableNote(models.Model):
project = models.ForeignKey(Project)
text = models.CharField(max_length=100)
def __unicode__(self):
return self.text
# A generic bound model
class GenericNote(SimpleModel, Sortable):
content_type = models.ForeignKey(ContentType,
@ -97,6 +116,7 @@ class Component(SimpleModel, Sortable):
return self.title
class Person(Sortable):
class Meta(Sortable.Meta):
verbose_name_plural = 'People'