how would i go about creating a user inn the database with a api call? Im using the Model.serializer, ive tried to override the save method and create a user with the request.data but i cant seem to get it to work. Any tips? The error that i get is that when i try to asign the user to the request.data it comes back saying that the value needs to be a user instance. How do i make the requested data a user instance? This is my code.
@api_view(['POST'])
def createUser(request):
serializer = userSerializer(data=request.data)
print(request.data['username'])
if serializer.is_valid():
serializer.save()
if request.data['password'] == request.data['password2']:
userModel = UserModel.objects.create(
user=request.data,
username=request.data['username'],
email=request.data['email'],
firstname=request.data['firstname'],
lastname=request.data['lastname'],
password=request.data['password'],
password2=request.data['password2']
)
userModel.save()
return Response('User was created')
else:
return Response('Passwords must match')
user=request.user.UserModel? Is it the same as the builtinUsermodel? Also why are you saving userModel again right after creating it?