Почему не хочет создавать юзера?
models.py
class UserProfile(User):
user = models.OneToOneField(User)
notification = models.CharField(max_length=500)
views.py
@api_view(['POST'])
def register_user(request):
"""
Example json:
{"username":"vaska", "password":"qwerty", "email":"example@gmail.com", "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'})
Ошибка:
UNIQUE constraint failed: auth_user.username