Fix SetPasswordHyperlinkedSerializer (update to new DRF)

This commit is contained in:
Santiago L 2021-10-07 14:11:50 +02:00
parent 008f49100f
commit 9a4f4ee17c

View file

@ -84,14 +84,14 @@ class SetPasswordHyperlinkedSerializer(HyperlinkedModelSerializer):
validators=[validate_password], write_only=True, required=False, validators=[validate_password], write_only=True, required=False,
style={'widget': widgets.PasswordInput}) style={'widget': widgets.PasswordInput})
def validate_password(self, attrs, source): def validate_password(self, value):
""" POST only password """ """ POST only password """
if self.instance: if self.instance:
if 'password' in attrs: if value:
raise serializers.ValidationError(_("Can not set password")) raise serializers.ValidationError(_("Can not set password"))
elif 'password' not in attrs: elif not value:
raise serializers.ValidationError(_("Password required")) raise serializers.ValidationError(_("Password required"))
return attrs return value
def validate(self, attrs): def validate(self, attrs):
""" remove password in case is not a real model field """ """ remove password in case is not a real model field """