How do I use this lib with User model's password field?
I have a custom User model with create_user method on User.objects, in an implementation similar to one shown here:
https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#a-full-example
If I user your Mixins, the password field is updated as a regular character field directly on the model, both on create() and update() (which is obvious).
For update(), I thought I could write my own update logic for password and then call super() like so:
def update(self, instance, validated_data):
user = self.context['request'].user
new_password = validated_data.pop('password', None)
if new_password and user.email == instance.email:
user.set_password(new_password)
user.save()
return super(UserSerializer, self).update(instance, validated_data)
but I'm getting an UniqueViolation error for the email field (it has an unique constraint, for obvious reasons). It's curious that my update() method is not even being called.
Even if the update() solution can be tweaked to work, I can't think of any solution for create().
Is there a way to solve this issue?