How can i validate an unique constraint with a key that is not on the request payload?
The key that i need to validate are user_id and sku but the request does not contain the user_id key.
Example of payload:
{'sku': '123', data: []}
The serializers:
class ProductConfiguration(serializers.Serializer):
min_quantity = serializers.IntegerField(required=True)
price = serializers.DecimalField(
required=True,
decimal_places=2,
max_digits=10,
coerce_to_string=False
)
class ProductSerializer(serializers.ModelSerializer):
sku = serializers.CharField(required=True)
data = ProductConfiguration(many=True, required=True)
class Meta:
model = WholeSale
# the "id" and "user_id" columns should not be included on the response
exclude = ['id', 'user']
I need to validate that the user and sku key already exist.
By default if the two keys user_id and sku were on the payload drf could take care of Unique error, how can i validate this two keys if one of them are not on the payload?