Add support to create Address via API

This commit is contained in:
Santiago L 2021-06-08 13:37:00 +02:00
parent 70f7551e7d
commit e1d71fa620
1 changed files with 10 additions and 0 deletions

View File

@ -54,3 +54,13 @@ class AddressSerializer(AccountSerializerMixin, serializers.HyperlinkedModelSeri
if not attrs['mailboxes'] and not attrs['forward']: if not attrs['mailboxes'] and not attrs['forward']:
raise serializers.ValidationError("A mailbox or forward address should be provided.") raise serializers.ValidationError("A mailbox or forward address should be provided.")
return attrs return attrs
def create(self, validated_data):
mailboxes = validated_data.pop('mailboxes')
# assign address to same account than domain
account = validated_data['domain'].account
obj = self.Meta.model.objects.create(account=account, **validated_data)
obj.mailboxes.set(mailboxes)
return obj