change title field in model Collection to translated JSON field (gm-165)
This commit is contained in:
parent
3d68f1ba29
commit
97823ea601
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:15
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
import utils.models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_title_json_from_title(apps, schema_editor):
|
||||||
|
# We can't import the Person model directly as it may be a newer
|
||||||
|
# version than this migration expects. We use the historical version.
|
||||||
|
Collection = apps.get_model('collection', 'Collection')
|
||||||
|
for collection in Collection.objects.all():
|
||||||
|
collection.name_json = {'en-GB': collection.name}
|
||||||
|
collection.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0014_auto_20191022_1242'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name_json',
|
||||||
|
field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='name'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_title_json_from_title, migrations.RunPython.noop),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='collection',
|
||||||
|
old_name='name_json',
|
||||||
|
new_name='name',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
field=utils.models.TJSONField(help_text='{"en-GB":"some text"}', verbose_name='name'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -43,9 +43,11 @@ class CollectionQuerySet(RelatedObjectsCountMixin):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
class Collection(ProjectBaseMixin, CollectionDateMixin,
|
||||||
TranslatedFieldsMixin, URLImageMixin):
|
TranslatedFieldsMixin, URLImageMixin):
|
||||||
"""Collection model."""
|
"""Collection model."""
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
ORDINARY = 0 # Ordinary collection
|
ORDINARY = 0 # Ordinary collection
|
||||||
POP = 1 # POP collection
|
POP = 1 # POP collection
|
||||||
|
|
||||||
|
|
@ -54,6 +56,8 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
(POP, _('Pop')),
|
(POP, _('Pop')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
name = TJSONField(verbose_name=_('name'),
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
||||||
default=ORDINARY,
|
default=ORDINARY,
|
||||||
verbose_name=_('Collection type'))
|
verbose_name=_('Collection type'))
|
||||||
|
|
@ -79,10 +83,6 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
verbose_name = _('collection')
|
verbose_name = _('collection')
|
||||||
verbose_name_plural = _('collections')
|
verbose_name_plural = _('collections')
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
"""String method."""
|
|
||||||
return f'{self.name}'
|
|
||||||
|
|
||||||
|
|
||||||
class GuideQuerySet(models.QuerySet):
|
class GuideQuerySet(models.QuerySet):
|
||||||
"""QuerySet for Guide."""
|
"""QuerySet for Guide."""
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,19 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from collection import models
|
from collection import models
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
class CollectionBaseSerializer(serializers.ModelSerializer):
|
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||||
"""Collection base serializer"""
|
"""Collection base serializer"""
|
||||||
# RESPONSE
|
name_translated = TranslatedField()
|
||||||
description_translated = serializers.CharField(read_only=True, allow_null=True)
|
description_translated = TranslatedField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name_translated',
|
||||||
'description_translated',
|
'description_translated',
|
||||||
'image_url',
|
'image_url',
|
||||||
'slug',
|
'slug',
|
||||||
|
|
@ -35,8 +36,7 @@ class CollectionSerializer(CollectionBaseSerializer):
|
||||||
queryset=location_models.Country.objects.all(),
|
queryset=location_models.Country.objects.all(),
|
||||||
write_only=True)
|
write_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(CollectionBaseSerializer.Meta):
|
||||||
model = models.Collection
|
|
||||||
fields = CollectionBaseSerializer.Meta.fields + [
|
fields = CollectionBaseSerializer.Meta.fields + [
|
||||||
'start',
|
'start',
|
||||||
'end',
|
'end',
|
||||||
|
|
|
||||||
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:50
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0019_award_image_url'),
|
||||||
|
('main', '0019_auto_20191022_1359'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue
Block a user