From 2089ca067a0ca0ede2344a04ee9a16f04935dc9e Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 20 Sep 2019 14:22:39 +0300 Subject: [PATCH] chane FK to URLField in Collection model, added properties to field collections in Establishment model --- .../migrations/0011_auto_20190920_1059.py | 22 +++++++++++++++++++ apps/collection/models.py | 8 +++---- apps/collection/serializers/common.py | 6 ----- .../migrations/0027_auto_20190920_1120.py | 18 +++++++++++++++ apps/establishment/models.py | 5 +++-- 5 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 apps/collection/migrations/0011_auto_20190920_1059.py create mode 100644 apps/establishment/migrations/0027_auto_20190920_1120.py diff --git a/apps/collection/migrations/0011_auto_20190920_1059.py b/apps/collection/migrations/0011_auto_20190920_1059.py new file mode 100644 index 00000000..ac3c21c5 --- /dev/null +++ b/apps/collection/migrations/0011_auto_20190920_1059.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.4 on 2019-09-20 10:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('collection', '0010_collection_description'), + ] + + operations = [ + migrations.RemoveField( + model_name='collection', + name='image', + ), + migrations.AddField( + model_name='collection', + name='image_url', + field=models.URLField(blank=True, default=None, null=True, verbose_name='Image URL path'), + ), + ] diff --git a/apps/collection/models.py b/apps/collection/models.py index 50af7ec7..a4a9bcae 100644 --- a/apps/collection/models.py +++ b/apps/collection/models.py @@ -4,7 +4,7 @@ from utils.models import TJSONField from django.db import models from django.utils.translation import gettext_lazy as _ -from utils.models import ProjectBaseMixin, ImageMixin +from utils.models import ProjectBaseMixin, URLImageMixin from utils.models import TranslatedFieldsMixin @@ -41,7 +41,8 @@ class CollectionQuerySet(models.QuerySet): return self.filter(is_publish=True) -class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin, TranslatedFieldsMixin): +class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin, + TranslatedFieldsMixin, URLImageMixin): """Collection model.""" ORDINARY = 0 # Ordinary collection POP = 1 # POP collection @@ -54,9 +55,6 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin, Tra collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES, default=ORDINARY, verbose_name=_('Collection type')) - image = models.ForeignKey( - 'gallery.Image', null=True, blank=True, default=None, - verbose_name=_('Collection image'), on_delete=models.CASCADE) is_publish = models.BooleanField( default=False, verbose_name=_('Publish status')) on_top = models.BooleanField( diff --git a/apps/collection/serializers/common.py b/apps/collection/serializers/common.py index 5e0029ee..85d66d30 100644 --- a/apps/collection/serializers/common.py +++ b/apps/collection/serializers/common.py @@ -1,14 +1,12 @@ from rest_framework import serializers from collection import models -from gallery import models as gallery_models from location import models as location_models class CollectionSerializer(serializers.ModelSerializer): """Collection serializer""" # RESPONSE - image_url = serializers.ImageField(source='image.image') description_translated = serializers.CharField(read_only=True, allow_null=True) # COMMON @@ -22,9 +20,6 @@ class CollectionSerializer(serializers.ModelSerializer): country = serializers.PrimaryKeyRelatedField( queryset=location_models.Country.objects.all(), write_only=True) - image = serializers.PrimaryKeyRelatedField( - queryset=gallery_models.Image.objects.all(), - write_only=True) class Meta: model = models.Collection @@ -34,7 +29,6 @@ class CollectionSerializer(serializers.ModelSerializer): 'description_translated', 'start', 'end', - 'image', 'image_url', 'is_publish', 'on_top', diff --git a/apps/establishment/migrations/0027_auto_20190920_1120.py b/apps/establishment/migrations/0027_auto_20190920_1120.py new file mode 100644 index 00000000..974b8093 --- /dev/null +++ b/apps/establishment/migrations/0027_auto_20190920_1120.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.4 on 2019-09-20 11:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('establishment', '0026_establishment_preview_image_url'), + ] + + operations = [ + migrations.AlterField( + model_name='establishment', + name='collections', + field=models.ManyToManyField(blank=True, default=None, null=True, related_name='establishments', to='collection.Collection', verbose_name='Collections'), + ), + ] diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 2841301f..f731cd74 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -272,8 +272,9 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin): transportation = models.TextField(blank=True, null=True, default=None, verbose_name=_('Transportation')) collections = models.ManyToManyField(to='collection.Collection', - verbose_name=_('Collections'), - related_name='establishments') + related_name='establishments', + blank=True, null=True, default=None, + verbose_name=_('Collections')) preview_image_url = models.URLField(verbose_name=_('Preview image URL path'), blank=True, null=True, default=None)