From e1d71fa620d15572dbc1749ae1fe3bc36eb1daa9 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 8 Jun 2021 13:37:00 +0200 Subject: [PATCH] Add support to create Address via API --- orchestra/contrib/mailboxes/serializers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/orchestra/contrib/mailboxes/serializers.py b/orchestra/contrib/mailboxes/serializers.py index 36471996..c0ab4639 100644 --- a/orchestra/contrib/mailboxes/serializers.py +++ b/orchestra/contrib/mailboxes/serializers.py @@ -54,3 +54,13 @@ class AddressSerializer(AccountSerializerMixin, serializers.HyperlinkedModelSeri if not attrs['mailboxes'] and not attrs['forward']: raise serializers.ValidationError("A mailbox or forward address should be provided.") 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