In django, creating a User has a different and unique flow from the usual Model instance creation. You need to call create_user()
which is a method of BaseUserManager
.
Since django REST framework's flow is to do restore_object()
and then save_object()
, it's not possible to simply create Users using a ModelSerializer
in a generic create API endpoint, without hacking you way through.
What would be a clean way to solve this? or at least get it working using django's built-in piping?
Edit:
Important to note that what's specifically not working is that once you try to authenticate the created user instance using django.contrib.auth.authenticate
it fails if the instance was simply created using User.objects.create()
and not .create_user()
.