Added country field
This commit is contained in:
parent
7edd836a75
commit
d4e993abee
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-31 01:31
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('location', '0033_merge_20191224_0920'),
|
||||
('notification', '0008_remove_subscribe_state'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subscriptiontype',
|
||||
name='country',
|
||||
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='Country'),
|
||||
),
|
||||
]
|
||||
19
apps/notification/migrations/0010_auto_20191231_0135.py
Normal file
19
apps/notification/migrations/0010_auto_20191231_0135.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 2.2.7 on 2019-12-31 01:35
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('notification', '0009_subscriptiontype_country'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscriptiontype',
|
||||
name='country',
|
||||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='location.Country', verbose_name='country'),
|
||||
),
|
||||
]
|
||||
|
|
@ -6,6 +6,7 @@ from django.utils.timezone import now
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from account.models import User
|
||||
from location.models import Country
|
||||
from utils.methods import generate_string_code
|
||||
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
||||
|
||||
|
|
@ -15,7 +16,9 @@ class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
|
|||
name = TJSONField(blank=True, null=True, default=None,
|
||||
verbose_name=_('name'),
|
||||
help_text='{"en-GB":"some text"}')
|
||||
# TODO: не хватает связи со страной. ForeignKey
|
||||
country = models.ForeignKey(Country, on_delete=models.PROTECT,
|
||||
blank=True, null=True, default=None,
|
||||
verbose_name=_('country'))
|
||||
|
||||
|
||||
# todo: associate user & subscriber after users registration
|
||||
|
|
@ -127,10 +130,6 @@ class Subscriber(ProjectBaseMixin):
|
|||
query = f'?code={self.update_code}'
|
||||
return f'{schema}://{site_domain}{url}{query}'
|
||||
|
||||
@property
|
||||
def subscribe_objects(self):
|
||||
return Subscribe.objects.filter(subscriber=self)
|
||||
|
||||
|
||||
class Subscribe(ProjectBaseMixin):
|
||||
"""Subscribe model."""
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from location.serializers import CountrySimpleSerializer
|
||||
from notification import models
|
||||
from utils.methods import get_user_ip
|
||||
from utils.serializers import TranslatedField
|
||||
|
|
@ -11,6 +12,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
|
|||
"""Subscription type serializer."""
|
||||
|
||||
name_translated = TranslatedField()
|
||||
country = CountrySimpleSerializer()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -20,6 +22,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
|
|||
'id',
|
||||
'index_name',
|
||||
'name_translated',
|
||||
'country',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -80,7 +83,7 @@ class SubscribeObjectSerializer(serializers.ModelSerializer):
|
|||
"""Meta class."""
|
||||
|
||||
model = models.Subscriber
|
||||
fields = ()
|
||||
fields = ('subscriber', )
|
||||
read_only_fields = ('subscribe_date', 'unsubscribe_date',)
|
||||
|
||||
|
||||
|
|
@ -88,8 +91,7 @@ class SubscribeSerializer(serializers.ModelSerializer):
|
|||
"""Subscribe serializer."""
|
||||
|
||||
email = serializers.EmailField(required=False, source='send_to')
|
||||
subscription_types = SubscriptionTypeSerializer(read_only=True, source='subscription_types_set')
|
||||
subscribe_objects = SubscribeObjectSerializer(read_only=True)
|
||||
subscription_types = SubscriptionTypeSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -99,5 +101,4 @@ class SubscribeSerializer(serializers.ModelSerializer):
|
|||
'email',
|
||||
'subscription_types',
|
||||
'link_to_unsubscribe',
|
||||
'subscribe_objects',
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user