From 661f417a7b14179ac9212a02e8bb7de3fc8b9e33 Mon Sep 17 00:00:00 2001 From: Brandon Taylor Date: Tue, 23 Apr 2013 08:05:40 -0400 Subject: [PATCH] Merged pull request from kynazz to add support for unicode in sort view title. Updated readme and version. --- README.md | 7 +++-- adminsortable/models.py | 33 ++++++++++++-------- sample_project/database/test_project.sqlite | Bin 54272 -> 54272 bytes 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f5f7ea3..039ba1c 100644 --- a/README.md +++ b/README.md @@ -129,10 +129,12 @@ SortableStackedInline: class MySortableStackedInline(SortableStackedInline): """Your inline options go here""" + There are also generic equivalents that you can inherit from: from adminsortable.admin import (SortableGenericTabularInline, SortableGenericStackedInline) + """Your generic inline options go here""" *** IMPORTANT *** @@ -160,9 +162,8 @@ ordering on top of that just seemed a little much in my opinion. django-admin-sortable is currently used in production. -### What's new in 1.4.1? -- Django 1.5 compatibility -- Support for Generic Inlines (thanks @Hedde!) +### What's new in 1.4.2? +- Unicode support for the sort view title (thanks @knyazz) ### Future diff --git a/adminsortable/models.py b/adminsortable/models.py index 49d6163..26cb682 100644 --- a/adminsortable/models.py +++ b/adminsortable/models.py @@ -14,22 +14,26 @@ class MultipleSortableForeignKeyException(Exception): class Sortable(models.Model): """ - Unfortunately, Django doesn't support using more than one AutoField in a model - or this class could be simplified. + Unfortunately, Django doesn't support using more than one AutoField + in a model or this class could be simplified. - `is_sortable` determines whether or not the Model is sortable by determining - if the last value of `order` is greater than the default of 1, which should be - present if there is only one object. + `is_sortable` determines whether or not the Model is sortable by + determining if the last value of `order` is greater than the default + of 1, which should be present if there is only one object. - `model_type_id` returns the ContentType.id for the Model that inherits Sortable + `model_type_id` returns the ContentType.id for the Model that + inherits Sortable - `save` the override of save increments the last/highest value of order by 1 + `save` the override of save increments the last/highest value of + order by 1 - Override `sortable_by` method to make your model be sortable by a foreign key field. - Set `sortable_by` to the class specified in the foreign key relationship. + Override `sortable_by` method to make your model be sortable by a + foreign key field. Set `sortable_by` to the class specified in the + foreign key relationship. """ - order = models.PositiveIntegerField(editable=False, default=1, db_index=True) + order = models.PositiveIntegerField(editable=False, default=1, + db_index=True) # legacy support sortable_by = None @@ -41,7 +45,8 @@ class Sortable(models.Model): @classmethod def is_sortable(cls): try: - max_order = cls.objects.aggregate(models.Max('order'))['order__max'] + max_order = cls.objects.aggregate( + models.Max('order'))['order__max'] except (TypeError, IndexError): max_order = 0 return True if max_order > 1 else False @@ -59,12 +64,14 @@ class Sortable(models.Model): if isinstance(field, SortableForeignKey): sortable_foreign_keys.append(field) if len(sortable_foreign_keys) > 1: - raise MultipleSortableForeignKeyException(u'%s may only have one SortableForeignKey' % self) + raise MultipleSortableForeignKeyException( + u'%s may only have one SortableForeignKey' % self) def save(self, *args, **kwargs): if not self.id: try: - self.order = self.__class__.objects.aggregate(models.Max('order'))['order__max'] + 1 + self.order = self.__class__.objects.aggregate( + models.Max('order'))['order__max'] + 1 except (TypeError, IndexError): pass diff --git a/sample_project/database/test_project.sqlite b/sample_project/database/test_project.sqlite index f8720d70e4f4c206f6e19f51fa17546661a66cb7..3e632311cd806f67aa36c692a392e6ccf1f42bb1 100644 GIT binary patch delta 308 zcmZoz!Q8Ndd4e?Km5DOWtXCLxAE|Cki7^*4GF31%u`)5VGPKk)HnXraw%mNlTwg$t zfq{XAVLAgdJ5w8DFOXq7u~CltmheYAE|6ii7^*4G*vLLurf8aGPKY$Ft9K(Hrjm2Twj2n znTvs$QG$UYsR$zsnQJ`T|R#Zlmi>HBa zRkE>fh@(lAi(^$}c;Mt-&z~HPWh|_|P1TN*3;h))>w8~hVPIe=o!D5&UeC(v+sNxU z`94s5tydHe7xN?rW@ZltW)J4v&3rzh%o8W5PxkOHQcO!VG)zoPOi40MGfPWNN;6I} zH8)BzOtDB!OflzsA8d)Oy X(b&M!f?bZ;k#Ta4m(=Ei_4XkEM1@c{