diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index 159bb9d..8392996 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals from copy import deepcopy +from adminsortable.admin import SortableAdmin from aldryn_apphooks_config.admin import BaseAppHookConfig, ModelAppHookConfig from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin from cms.models import CMSPlugin, ValidationError @@ -73,7 +74,7 @@ class BlogCategoryAdmin(EnhancedModelAdminMixin, ModelAppHookConfig, Translatabl class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin, - ModelAppHookConfig, TranslatableAdmin): + ModelAppHookConfig, TranslatableAdmin, SortableAdmin): form = PostAdminForm list_display = [ 'title', 'author', 'date_published', 'app_config', 'all_languages_column', diff --git a/djangocms_blog/migrations/0030_auto_20170411_1456.py b/djangocms_blog/migrations/0030_auto_20170411_1456.py new file mode 100644 index 0000000..91ae84b --- /dev/null +++ b/djangocms_blog/migrations/0030_auto_20170411_1456.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-11 09:26 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_blog', '0029_post_related'), + ] + + operations = [ + migrations.AlterModelOptions( + name='post', + options={'get_latest_by': 'date_published', 'ordering': ('post_order', '-date_published', '-date_created'), 'verbose_name': 'blog article', 'verbose_name_plural': 'blog articles'}, + ), + migrations.AddField( + model_name='post', + name='post_order', + field=models.PositiveIntegerField(db_index=True, default=0, editable=False), + ), + ] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 8d34aac..c8d832c 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals import hashlib +from adminsortable.models import SortableMixin from aldryn_apphooks_config.fields import AppHookConfigField from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager from cms.models import CMSPlugin, PlaceholderField @@ -130,7 +131,7 @@ class BlogCategory(TranslatableModel): @python_2_unicode_compatible -class Post(KnockerModel, ModelMeta, TranslatableModel): +class Post(SortableMixin, KnockerModel, ModelMeta, TranslatableModel): """ Blog post """ @@ -195,6 +196,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel): verbose_name=_('Related Posts'), blank=True, symmetrical=False) + post_order = models.PositiveIntegerField(default=0, editable=False, db_index=True) _metadata = { 'title': 'get_title', @@ -227,7 +229,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel): class Meta: verbose_name = _('blog article') verbose_name_plural = _('blog articles') - ordering = ('-date_published', '-date_created') + ordering = ('post_order', '-date_published', '-date_created') get_latest_by = 'date_published' def __str__(self): diff --git a/setup.py b/setup.py index 55bce8d..c9642d2 100755 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ setup( 'django-meta-mixin>=0.3', 'aldryn-apphooks-config>=0.2.6', 'djangocms-apphook-setup', + 'django-admin-sortable', ], extras_require={ 'search': ['aldryn-search'],