I'am developing a website in Python Django. I have two "class CustomUser" it is used in order to login and another "class coach", this class contains information about users. I need to match these two class. My website identify the user who is logged in but it fail to assign this user a coach class. When I try to submit my form I receive the error "Cannot assign "'prof'": "coach.user" must be a "CustomUser" instance." I'am a beginner in Python Django. Can you help me to resolve this problem ?
This is Site/models.py
class coach(models.Model):
user = models.OneToOneField(CustomUser,on_delete=models.CASCADE)
Telephone = models.IntegerField()
Level = models.TextField()
Study = models.TextField()
This is my users/models.py
from django.contrib.auth.models import AbstractUser, UserManager
from django.db import models
class CustomUserManager(UserManager):
pass
class CustomUser(AbstractUser):
objects = CustomUserManager()
This is my Site/views.py there I have a function which find the user and assign him a coach class.
def Register(request):
form = ContactForm(request.POST or None, request.FILES)
if form.is_valid():
obj = form.save(commit=False)
obj.user = request.user.username
obj.save()
form.save()
return render(request, 'Register.html', {'form': form})