From ef59216feb9592871f54ec8c3322f4c08cefad32 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmenko Date: Sun, 1 Sep 2019 13:39:01 +0300 Subject: [PATCH] change contacts for est. --- apps/establishment/admin.py | 15 ++----- .../migrations/0007_auto_20190901_1032.py | 30 ++++++++++++++ .../0008_contactemail_contactphone.py | 39 +++++++++++++++++++ apps/establishment/models.py | 19 ++------- apps/establishment/serializers.py | 21 ++-------- .../migrations/0013_auto_20190901_1032.py | 35 +++++++++++++++++ .../migrations/0009_auto_20190901_1032.py | 29 ++++++++++++++ .../migrations/0003_auto_20190901_1032.py | 19 +++++++++ 8 files changed, 163 insertions(+), 44 deletions(-) create mode 100644 apps/establishment/migrations/0007_auto_20190901_1032.py create mode 100644 apps/establishment/migrations/0008_contactemail_contactphone.py create mode 100644 apps/main/migrations/0013_auto_20190901_1032.py create mode 100644 apps/news/migrations/0009_auto_20190901_1032.py create mode 100644 apps/translation/migrations/0003_auto_20190901_1032.py diff --git a/apps/establishment/admin.py b/apps/establishment/admin.py index a5209c3d..37a2e8cb 100644 --- a/apps/establishment/admin.py +++ b/apps/establishment/admin.py @@ -37,21 +37,12 @@ class ContactEmailInline(admin.TabularInline): extra = 0 -@admin.register(models.Contact) -class ContactAdmin(admin.ModelAdmin): - """Contact admin.""" - inlines = [ContactPhoneInline, ContactEmailInline, ] - - -class ContactsInline(admin.TabularInline): - model = models.Contact - extra = 0 - - @admin.register(models.Establishment) class EstablishmentAdmin(admin.ModelAdmin): """Establishment admin.""" - inlines = [AwardInline, MetaDataContentInline, ContactsInline, ] + inlines = [ + AwardInline, MetaDataContentInline, + ContactPhoneInline, ContactEmailInline] @admin.register(models.EstablishmentSchedule) diff --git a/apps/establishment/migrations/0007_auto_20190901_1032.py b/apps/establishment/migrations/0007_auto_20190901_1032.py new file mode 100644 index 00000000..eb6c6a4a --- /dev/null +++ b/apps/establishment/migrations/0007_auto_20190901_1032.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.4 on 2019-09-01 10:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('establishment', '0006_merge_20190901_0846'), + ] + + operations = [ + migrations.RemoveField( + model_name='contactemail', + name='contact', + ), + migrations.RemoveField( + model_name='contactphone', + name='contact', + ), + migrations.DeleteModel( + name='Contact', + ), + migrations.DeleteModel( + name='ContactEmail', + ), + migrations.DeleteModel( + name='ContactPhone', + ), + ] diff --git a/apps/establishment/migrations/0008_contactemail_contactphone.py b/apps/establishment/migrations/0008_contactemail_contactphone.py new file mode 100644 index 00000000..bda629ed --- /dev/null +++ b/apps/establishment/migrations/0008_contactemail_contactphone.py @@ -0,0 +1,39 @@ +# Generated by Django 2.2.4 on 2019-09-01 10:36 + +from django.db import migrations, models +import django.db.models.deletion +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('establishment', '0007_auto_20190901_1032'), + ] + + operations = [ + migrations.CreateModel( + name='ContactPhone', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('phone', phonenumber_field.modelfields.PhoneNumberField(max_length=128)), + ('establishment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='phones', to='establishment.Establishment')), + ], + options={ + 'verbose_name': 'contact phone', + 'verbose_name_plural': 'contact phones', + }, + ), + migrations.CreateModel( + name='ContactEmail', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('email', models.EmailField(max_length=254)), + ('establishment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='emails', to='establishment.Establishment')), + ], + options={ + 'verbose_name': 'contact email', + 'verbose_name_plural': 'contact emails', + }, + ), + ] diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 0c73b722..8f346564 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -165,21 +165,10 @@ class EstablishmentSchedule(BaseAttributes): verbose_name_plural = _('Establishment schedules') -class Contact(models.Model): - """Contact model.""" - establishment = models.ForeignKey( - Establishment, related_name='contacts', on_delete=models.CASCADE) - address = models.ForeignKey('location.Address', on_delete=models.CASCADE) - - class Meta: - verbose_name = _('contact') - verbose_name_plural = _('contacts') - - class ContactPhone(models.Model): """Contact phone model.""" - contact = models.ForeignKey( - Contact, related_name='phones', on_delete=models.CASCADE) + establishment = models.ForeignKey( + Establishment, related_name='phones', on_delete=models.CASCADE) phone = PhoneNumberField() class Meta: @@ -192,8 +181,8 @@ class ContactPhone(models.Model): class ContactEmail(models.Model): """Contact email model.""" - contact = models.ForeignKey( - Contact, related_name='emails', on_delete=models.CASCADE) + establishment = models.ForeignKey( + Establishment, related_name='emails', on_delete=models.CASCADE) email = models.EmailField() class Meta: diff --git a/apps/establishment/serializers.py b/apps/establishment/serializers.py index 92c7bb1c..7e3a8085 100644 --- a/apps/establishment/serializers.py +++ b/apps/establishment/serializers.py @@ -24,21 +24,6 @@ class ContactEmailsSerializer(serializers.ModelSerializer): ] -class ContactSerializer(serializers.ModelSerializer): - """Contact serializer.""" - address = AddressSerializer(read_only=True) - phones = ContactPhonesSerializer(read_only=True, many=True,) - emails = ContactEmailsSerializer(read_only=True, many=True,) - - class Meta: - model = models.Contact - fields = [ - 'address', - 'phones', - 'emails' - ] - - class EstablishmentTypeSerializer(serializers.ModelSerializer): """Serializer for EstablishmentType model.""" @@ -92,7 +77,8 @@ class EstablishmentSerializer(serializers.ModelSerializer): schedule = EstablishmentScheduleSerializer(source='schedule.schedule', many=True, allow_null=True) - contacts = ContactSerializer(read_only=True, many=True, ) + phones = ContactPhonesSerializer(read_only=True, many=True, ) + emails = ContactEmailsSerializer(read_only=True, many=True, ) class Meta: """Meta class.""" @@ -113,7 +99,8 @@ class EstablishmentSerializer(serializers.ModelSerializer): 'tags', 'awards', 'schedule', - 'contacts' + 'phones', + 'emails' ) diff --git a/apps/main/migrations/0013_auto_20190901_1032.py b/apps/main/migrations/0013_auto_20190901_1032.py new file mode 100644 index 00000000..95c86883 --- /dev/null +++ b/apps/main/migrations/0013_auto_20190901_1032.py @@ -0,0 +1,35 @@ +# Generated by Django 2.2.4 on 2019-09-01 10:32 + +from django.db import migrations, models +import utils.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0012_auto_20190829_1155'), + ] + + operations = [ + migrations.CreateModel( + name='Currency', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='name')), + ], + options={ + 'verbose_name': 'currency', + 'verbose_name_plural': 'currencies', + }, + ), + migrations.AlterField( + model_name='award', + name='title', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='title'), + ), + migrations.AlterField( + model_name='metadata', + name='label', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='label'), + ), + ] diff --git a/apps/news/migrations/0009_auto_20190901_1032.py b/apps/news/migrations/0009_auto_20190901_1032.py new file mode 100644 index 00000000..5a083240 --- /dev/null +++ b/apps/news/migrations/0009_auto_20190901_1032.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.4 on 2019-09-01 10:32 + +from django.db import migrations +import utils.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0008_auto_20190828_1522'), + ] + + operations = [ + migrations.AlterField( + model_name='news', + name='description', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='news', + name='subtitle', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='subtitle'), + ), + migrations.AlterField( + model_name='news', + name='title', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='title'), + ), + ] diff --git a/apps/translation/migrations/0003_auto_20190901_1032.py b/apps/translation/migrations/0003_auto_20190901_1032.py new file mode 100644 index 00000000..85bf63eb --- /dev/null +++ b/apps/translation/migrations/0003_auto_20190901_1032.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.4 on 2019-09-01 10:32 + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('translation', '0002_siteinterfacedictionary'), + ] + + operations = [ + migrations.AlterField( + model_name='siteinterfacedictionary', + name='text', + field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='Text'), + ), + ]