diff --git a/adminsortable/admin.py b/adminsortable/admin.py index 6ba6c4e..937b286 100644 --- a/adminsortable/admin.py +++ b/adminsortable/admin.py @@ -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' diff --git a/sample_project/app/admin.py b/sample_project/app/admin.py index b4abba5..4975ae0 100644 --- a/sample_project/app/admin.py +++ b/sample_project/app/admin.py @@ -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) diff --git a/sample_project/app/models.py b/sample_project/app/models.py index ec31108..a1ea4f1 100644 --- a/sample_project/app/models.py +++ b/sample_project/app/models.py @@ -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) \ No newline at end of file diff --git a/sample_project/database/test_project.sqlite b/sample_project/database/test_project.sqlite index f7fe821..f8720d7 100644 Binary files a/sample_project/database/test_project.sqlite and b/sample_project/database/test_project.sqlite differ diff --git a/sample_project/manage.py b/sample_project/manage.py index 9c651f3..007cd0d 100644 --- a/sample_project/manage.py +++ b/sample_project/manage.py @@ -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")