Django 1.8 compatible
This commit is contained in:
parent
85eb7a319a
commit
aac62b1aef
3 changed files with 37 additions and 2 deletions
9
djangocms_blog/fields.py
Normal file
9
djangocms_blog/fields.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.db.models import SlugField
|
||||
|
||||
__all__ = ['AutoSlugField']
|
||||
|
||||
|
||||
class AutoSlugField(SlugField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.allow_unicode = kwargs.pop('allow_unicode', False)
|
||||
super(SlugField, self).__init__(*args, **kwargs)
|
21
djangocms_blog/migrations/0032_auto_20170722_1058.py
Normal file
21
djangocms_blog/migrations/0032_auto_20170722_1058.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-07-22 05:28
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
import djangocms_blog.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangocms_blog', '0031_auto_20170610_1744'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='posttranslation',
|
||||
name='slug',
|
||||
field=djangocms_blog.fields.AutoSlugField(allow_unicode=True, blank=True, db_index=False, max_length=255, verbose_name='slug'),
|
||||
),
|
||||
]
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
|
||||
import hashlib
|
||||
|
||||
import django
|
||||
from aldryn_apphooks_config.fields import AppHookConfigField
|
||||
from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager
|
||||
from cms.models import CMSPlugin, PlaceholderField
|
||||
|
@ -29,6 +30,7 @@ from sortedm2m.fields import SortedManyToManyField
|
|||
from taggit_autosuggest.managers import TaggableManager
|
||||
|
||||
from .cms_appconfig import BlogConfig
|
||||
from .fields import AutoSlugField
|
||||
from .managers import GenericDateTaggedManager
|
||||
from .settings import get_setting
|
||||
|
||||
|
@ -172,7 +174,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
|
||||
translations = TranslatedFields(
|
||||
title=models.CharField(_('title'), max_length=255),
|
||||
slug=models.SlugField(_('slug'), max_length=255, blank=True,
|
||||
slug=AutoSlugField(_('slug'), max_length=255, blank=True,
|
||||
db_index=True, allow_unicode=True),
|
||||
abstract=HTMLField(_('abstract'), blank=True, default=''),
|
||||
meta_description=models.TextField(verbose_name=_('post meta description'),
|
||||
|
@ -259,7 +261,10 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
if self.publish and self.date_published is None:
|
||||
self.date_published = timezone.now()
|
||||
if not self.slug and self.title:
|
||||
self.slug = slugify(self.title, allow_unicode=True)
|
||||
if django.VERSION >= (1, 9):
|
||||
self.slug = slugify(self.title, allow_unicode=True)
|
||||
else:
|
||||
self.slug = slugify(self.title)
|
||||
super(Post, self).save(*args, **kwargs)
|
||||
|
||||
def save_translation(self, translation, *args, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue