Ejemplo n.º 1
0
    def create(self, validated_data):
        address = validated_data.pop('address')
        user = Customuser(**validated_data)
        user.save()
        serializer = AddressSerializer(data=address)
        if serializer.is_valid(raise_exception=True):
            serializer.save(customuser=user)

        return user
Ejemplo n.º 2
0
def test_serializer_create():
    address = {
        "street": "test test",
        "number": 10,
        "zip_code": "00000000",
        "city": "SP",
        "state": "SP"
    }
    serializer = AddressSerializer(data=address)
    serializer.is_valid(raise_exception=True)
    serializer.save()
Ejemplo n.º 3
0
 def _get_or_create_address(self, validated_data):
     address = validated_data.pop('address')
     address_serializer = AddressSerializer(data=address)
     address_serializer.is_valid(raise_exception=True)
     return address_serializer.save()