Post ordering functionality added

This commit is contained in:
Dipen Patel 2017-04-11 15:06:37 +05:30
parent c2b97edb24
commit eebe16c8f5
4 changed files with 31 additions and 3 deletions

View file

@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
from copy import deepcopy from copy import deepcopy
from adminsortable.admin import SortableAdmin
from aldryn_apphooks_config.admin import BaseAppHookConfig, ModelAppHookConfig from aldryn_apphooks_config.admin import BaseAppHookConfig, ModelAppHookConfig
from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin
from cms.models import CMSPlugin, ValidationError from cms.models import CMSPlugin, ValidationError
@ -73,7 +74,7 @@ class BlogCategoryAdmin(EnhancedModelAdminMixin, ModelAppHookConfig, Translatabl
class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin, class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
ModelAppHookConfig, TranslatableAdmin): ModelAppHookConfig, TranslatableAdmin, SortableAdmin):
form = PostAdminForm form = PostAdminForm
list_display = [ list_display = [
'title', 'author', 'date_published', 'app_config', 'all_languages_column', 'title', 'author', 'date_published', 'app_config', 'all_languages_column',

View file

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

View file

@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import hashlib import hashlib
from adminsortable.models import SortableMixin
from aldryn_apphooks_config.fields import AppHookConfigField from aldryn_apphooks_config.fields import AppHookConfigField
from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager
from cms.models import CMSPlugin, PlaceholderField from cms.models import CMSPlugin, PlaceholderField
@ -130,7 +131,7 @@ class BlogCategory(TranslatableModel):
@python_2_unicode_compatible @python_2_unicode_compatible
class Post(KnockerModel, ModelMeta, TranslatableModel): class Post(SortableMixin, KnockerModel, ModelMeta, TranslatableModel):
""" """
Blog post Blog post
""" """
@ -195,6 +196,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
verbose_name=_('Related Posts'), verbose_name=_('Related Posts'),
blank=True, blank=True,
symmetrical=False) symmetrical=False)
post_order = models.PositiveIntegerField(default=0, editable=False, db_index=True)
_metadata = { _metadata = {
'title': 'get_title', 'title': 'get_title',
@ -227,7 +229,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
class Meta: class Meta:
verbose_name = _('blog article') verbose_name = _('blog article')
verbose_name_plural = _('blog articles') verbose_name_plural = _('blog articles')
ordering = ('-date_published', '-date_created') ordering = ('post_order', '-date_published', '-date_created')
get_latest_by = 'date_published' get_latest_by = 'date_published'
def __str__(self): def __str__(self):

View file

@ -40,6 +40,7 @@ setup(
'django-meta-mixin>=0.3', 'django-meta-mixin>=0.3',
'aldryn-apphooks-config>=0.2.6', 'aldryn-apphooks-config>=0.2.6',
'djangocms-apphook-setup', 'djangocms-apphook-setup',
'django-admin-sortable',
], ],
extras_require={ extras_require={
'search': ['aldryn-search'], 'search': ['aldryn-search'],