Merge branch 'feature/collection-slugs' into 'develop'
Feature/collection slugs See merge request gm/gm-backend!181
This commit is contained in:
commit
cd7ba1996d
18
apps/collection/migrations/0027_auto_20191217_1852.py
Normal file
18
apps/collection/migrations/0027_auto_20191217_1852.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-17 18:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('collection', '0026_merge_20191217_1151'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='collection',
|
||||
name='slug',
|
||||
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Collection slug'),
|
||||
),
|
||||
]
|
||||
|
|
@ -13,6 +13,8 @@ from utils.models import (
|
|||
from utils.querysets import RelatedObjectsCountMixin
|
||||
from utils.models import IntermediateGalleryModelMixin, GalleryMixin
|
||||
|
||||
from slugify import slugify
|
||||
|
||||
|
||||
# Mixins
|
||||
class CollectionNameMixin(models.Model):
|
||||
|
|
@ -79,7 +81,7 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
|
|||
description = TJSONField(
|
||||
_('description'), null=True, blank=True,
|
||||
default=None, help_text='{"en-GB":"some text"}')
|
||||
slug = models.SlugField(max_length=50, unique=True,
|
||||
slug = models.SlugField(max_length=255, unique=True,
|
||||
verbose_name=_('Collection slug'), editable=True, null=True)
|
||||
old_id = models.IntegerField(null=True, blank=True)
|
||||
|
||||
|
|
@ -141,6 +143,15 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
|
|||
|
||||
return related_objects
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
slugify_slug = slugify(
|
||||
next(iter(self.name.values())),
|
||||
word_boundary=True
|
||||
)
|
||||
self.slug = slugify_slug
|
||||
super(Collection, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class GuideTypeQuerySet(models.QuerySet):
|
||||
"""QuerySet for model GuideType."""
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ class CollectionBackOfficeSerializer(CollectionBaseSerializer):
|
|||
'related_object_names',
|
||||
'rank',
|
||||
]
|
||||
extra_kwargs = {
|
||||
'slug': {'read_only': True},
|
||||
}
|
||||
|
||||
|
||||
class CollectionBindObjectSerializer(serializers.Serializer):
|
||||
|
|
|
|||
|
|
@ -64,5 +64,8 @@ pycountry==19.8.18
|
|||
# sql-tree
|
||||
django-mptt==0.9.1
|
||||
|
||||
# slugify
|
||||
python-slugify==4.0.0
|
||||
|
||||
# Export to Excel
|
||||
XlsxWriter==1.2.6
|
||||
Loading…
Reference in New Issue
Block a user