added generic inlines support
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from adminsortable.admin import (SortableAdmin, SortableTabularInline,
|
||||
SortableStackedInline)
|
||||
from app.models import Category, Project, Credit, Note
|
||||
SortableStackedInline, SortableGenericStackedInline)
|
||||
from app.models import Category, Project, Credit, Note, GenericNote
|
||||
|
||||
|
||||
admin.site.register(Category, SortableAdmin)
|
||||
@@ -17,8 +17,13 @@ class NoteInline(SortableStackedInline):
|
||||
extra = 0
|
||||
|
||||
|
||||
class GenericNoteInline(SortableGenericStackedInline):
|
||||
model = GenericNote
|
||||
extra = 0
|
||||
|
||||
|
||||
class ProjectAdmin(SortableAdmin):
|
||||
inlines = [CreditInline, NoteInline]
|
||||
inlines = [CreditInline, NoteInline, GenericNoteInline]
|
||||
list_display = ['__unicode__', 'category']
|
||||
|
||||
admin.site.register(Project, ProjectAdmin)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
|
||||
from adminsortable.fields import SortableForeignKey
|
||||
@@ -58,3 +60,16 @@ class Note(Sortable):
|
||||
|
||||
def __unicode__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
#a generic bound model
|
||||
class GenericNote(SimpleModel, Sortable):
|
||||
content_type = models.ForeignKey(ContentType, verbose_name=u"Content type", related_name="generic_notes")
|
||||
object_id = models.PositiveIntegerField(u"Content id")
|
||||
content_object = generic.GenericForeignKey(ct_field='content_type', fk_field='object_id')
|
||||
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s : %s" % (self.title, self.content_object)
|
||||
Reference in New Issue
Block a user