Merged pull request 97
This commit is contained in:
@@ -71,13 +71,13 @@ class ProjectAdmin(SortableAdmin):
|
||||
CreditInline, NoteInline, GenericNoteInline,
|
||||
NonSortableCreditInline, NonSortableNoteInline
|
||||
]
|
||||
list_display = ['__unicode__', 'category']
|
||||
list_display = ['__str__', 'category']
|
||||
|
||||
admin.site.register(Project, ProjectAdmin)
|
||||
|
||||
|
||||
class PersonAdmin(SortableAdmin):
|
||||
list_display = ['__unicode__', 'is_board_member']
|
||||
list_display = ['__str__', 'is_board_member']
|
||||
|
||||
admin.site.register(Person, PersonAdmin)
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
from adminsortable.fields import SortableForeignKey
|
||||
from adminsortable.models import Sortable
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class SimpleModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
title = models.CharField(max_length=50)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
@@ -28,11 +30,12 @@ class Category(SimpleModel, Sortable):
|
||||
|
||||
|
||||
# A model with an override of its queryset for admin
|
||||
@python_2_unicode_compatible
|
||||
class Widget(SimpleModel, Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
@@ -47,6 +50,7 @@ class Project(SimpleModel, Sortable):
|
||||
|
||||
|
||||
# Registered as a tabular inline on `Project`
|
||||
@python_2_unicode_compatible
|
||||
class Credit(Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
@@ -55,11 +59,12 @@ class Credit(Sortable):
|
||||
first_name = models.CharField(max_length=30)
|
||||
last_name = models.CharField(max_length=30)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return '{0} {1}'.format(self.first_name, self.last_name)
|
||||
|
||||
|
||||
# Registered as a stacked inline on `Project`
|
||||
@python_2_unicode_compatible
|
||||
class Note(Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
@@ -67,30 +72,33 @@ class Note(Sortable):
|
||||
project = models.ForeignKey(Project)
|
||||
text = models.CharField(max_length=100)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
# Registered as a tabular inline on `Project` which can't be sorted
|
||||
@python_2_unicode_compatible
|
||||
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):
|
||||
def __str__(self):
|
||||
return '{0} {1}'.format(self.first_name, self.last_name)
|
||||
|
||||
|
||||
# Registered as a stacked inline on `Project` which can't be sorted
|
||||
@python_2_unicode_compatible
|
||||
class NonSortableNote(models.Model):
|
||||
project = models.ForeignKey(Project)
|
||||
text = models.CharField(max_length=100)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
# A generic bound model
|
||||
@python_2_unicode_compatible
|
||||
class GenericNote(SimpleModel, Sortable):
|
||||
content_type = models.ForeignKey(ContentType,
|
||||
verbose_name=u"Content type", related_name="generic_notes")
|
||||
@@ -101,22 +109,23 @@ class GenericNote(SimpleModel, Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return u'{0}: {1}'.format(self.title, self.content_object)
|
||||
|
||||
|
||||
# An model registered as an inline that has a custom queryset
|
||||
@python_2_unicode_compatible
|
||||
class Component(SimpleModel, Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
pass
|
||||
|
||||
widget = SortableForeignKey(Widget)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Person(Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
verbose_name_plural = 'People'
|
||||
@@ -134,19 +143,21 @@ class Person(Sortable):
|
||||
('Non-Board Members', {'is_board_member': False}),
|
||||
)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return '{0} {1}'.format(self.first_name, self.last_name)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class NonSortableCategory(SimpleModel):
|
||||
class Meta(SimpleModel.Meta):
|
||||
verbose_name = 'Non-Sortable Category'
|
||||
verbose_name_plural = 'Non-Sortable Categories'
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class SortableCategoryWidget(SimpleModel, Sortable):
|
||||
class Meta(Sortable.Meta):
|
||||
verbose_name = 'Sortable Category Widget'
|
||||
@@ -154,20 +165,21 @@ class SortableCategoryWidget(SimpleModel, Sortable):
|
||||
|
||||
non_sortable_category = SortableForeignKey(NonSortableCategory)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class SortableNonInlineCategory(SimpleModel, Sortable):
|
||||
"""Example of a model that is sortable, but has a SortableForeignKey
|
||||
that is *not* sortable, and is also not defined as an inline of the
|
||||
SortableForeignKey field."""
|
||||
|
||||
non_sortable_category = SortableForeignKey(NonSortableCategory)
|
||||
|
||||
class Meta(Sortable.Meta):
|
||||
verbose_name = 'Sortable Non-Inline Category'
|
||||
verbose_name_plural = 'Sortable Non-Inline Categories'
|
||||
|
||||
non_sortable_category = SortableForeignKey(NonSortableCategory)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
Reference in New Issue
Block a user