Answer the question
In order to leave comments, you need to log in
Why does not save users?
Why does not want to create a user?
models.py
class UserProfile(User):
user = models.OneToOneField(User)
notification = models.CharField(max_length=500)
@api_view(['POST'])
def register_user(request):
"""
Example json:
{"username":"vaska", "password":"qwerty", "email":"[email protected]", "first_name":"Vasya", "last_name":"Pupkin", "notification":"qweasdsdgfdfhdfhdfgdfhdfhffhdfh"}
"""
if request.method == 'POST':
if User.objects.filter(username = request.data['username']).exists():
return Response({'status':'User with this username already exist!'})
else:
if User.objects.filter(email = request.data['email']).exists():
return Response({'status':'User with this email already exist!'})
else:
new_user = User.objects.create_user(username=request.data['username'], password=request.data['password'], email = request.data['email'], first_name = request.data['first_name'], last_name = request.data['last_name'])
print request.data['notification']
profile = UserProfile(user=new_user, notification = request.data['notification'])
print profile
profile.save()
return Response({'status':'ok'})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question