added generic inlines support

master
intelliadmin 2013-03-15 10:10:01 +01:00
parent ddbeca7177
commit 279477da7b
5 changed files with 38 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import json
from django import VERSION as DJANGO_VERSION
from django.contrib.contenttypes.generic import GenericStackedInline, GenericTabularInline
DJANGO_MINOR_VERSION = DJANGO_VERSION[1]
from django.conf import settings
@ -238,3 +240,13 @@ class SortableTabularInline(SortableInlineBase, TabularInline):
class SortableStackedInline(SortableInlineBase, StackedInline):
"""Custom template that enables sorting for stacked inlines"""
template = 'adminsortable/edit_inline/stacked.html'
class SortableGenericTabularInline(SortableInlineBase, GenericTabularInline):
"""Custom template that enables sorting for tabular inlines"""
template = 'adminsortable/edit_inline/tabular.html'
class SortableGenericStackedInline(SortableInlineBase, GenericStackedInline):
"""Custom template that enables sorting for stacked inlines"""
template = 'adminsortable/edit_inline/stacked.html'

View File

@ -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)

View File

@ -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)

View File

@ -2,6 +2,9 @@
import os
import sys
# Adds the adminsortable package from the cloned repository instead of site_packages
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings")