Handle missing url attribute on write requests

This commit is contained in:
Santiago L 2021-07-08 12:25:29 +02:00
parent b365580165
commit 7d6a2474ab
1 changed files with 11 additions and 8 deletions

View File

@ -64,7 +64,10 @@ class HyperlinkedModelSerializer(serializers.HyperlinkedModelSerializer):
class RelatedHyperlinkedModelSerializer(HyperlinkedModelSerializer):
""" returns object on to_internal_value based on URL """
def to_internal_value(self, data):
try:
url = data.get('url')
except AttributeError:
url = None
if not url:
raise ValidationError({
'url': "URL is required."