gault-millau/apps/transfer/serializers/notification.py
2019-10-23 14:17:34 +05:00

35 lines
916 B
Python

from rest_framework import serializers
from notification.models import Subscriber
class SubscriberSerializer(serializers.ModelSerializer):
email = serializers.CharField()
locale = serializers.CharField(allow_null=True)
country_code = serializers.CharField(allow_null=True)
class Meta:
model = Subscriber
fields = (
"email",
"locale",
"country_code"
)
def validate(self, data):
data["email"] = self.get_email(data)
data["locale"] = self.get_locale(data)
data["country_code"] = self.get_country_code(data)
return data
def create(self, validated_data):
Subscriber.objects.create(**validated_data)
def get_email(self, obj):
return obj["email"]
def get_locale(self, obj):
return obj["locale"]
def get_country_code(self, obj):
return obj["country_code"]