'User' object has no attribute 'user_type' - Django Custom User model issue

I've created a custom user abstract model and profile model to collect additional information once the user registers.

I am collecting "User type: Employer/employee" at the time of registration but this doesn't seem to be recognized in the profile view. Despite the user being correctly added into the DB (I checked via Admin).

For example, I created user: asus23910 (employer user type). But when I login and redirect to, I get following error:

'User' object has no attribute 'user_type'C:\Users\ASUS\PycharmProjects\Content\content\content\views.py, line 112, in employer_profile_view

1. Here's my employer_profile_view.py code:

def employer_profile_view(request, username):
    user = User.objects.get(username=username)
    if user.user_type != User.EMPLOYER:
        # Redirect to the correct profile page if the user type is not employer
        return redirect('employee_profile', username=request.user.username)

    if request.method == 'POST':
        form = EmployerProfileForm(request.POST, instance=user.employerprofile)
        if form.is_valid():
            employer_profile = form.save(commit=False)
            employer_profile.user = user
            return redirect('employer_profile', username=request.user.username)
        form = EmployerProfileForm(instance=user.employerprofile)

    context = {
        'form': form,
        'username': username,
    return render(request, 'employer_profile.html', context)

2. Employer Profile model and connector

class EmployerProfile(models.Model):
   user = models.OneToOneField(User, on_delete=models.CASCADE)
   user_type = models.CharField(
   first_name = models.CharField(max_length=255)
   last_name = models.CharField(max_length=255)
   title = models.CharField(max_length=255)
   company_name = models.CharField(max_length=255)
   company_logo = models.ImageField(upload_to='company_logos/')
   company_location = models.CharField(max_length=255)
   company_website = models.URLField()
   company_twitter = models.URLField()

#one-2-one connector
@receiver(post_save, sender=User)
def create_employer_profile(sender, instance, created, **kwargs):
   if created:
       EmployerProfile.objects.create(user=instance, user_type=instance.user_type)
       print('Employer Profile created')

@receiver(post_save, sender=User)
def save_employer_profile(sender, instance, **kwargs):
   instance.employerprofile.user_type = instance.user_type
   print('Employer Profile saved')

3. User model

#model one to store the user into db
class User(AbstractUser):
    EMPLOYER = "employer"
    EMPLOYEE = "employee"
        (EMPLOYER, "Employer"),
        (EMPLOYEE, "Employee"),
    user_type = models.CharField(
    email = models.EmailField(default='example@example.com')
    username = models.CharField(max_length=150, default='example_user')
    password = models.CharField(max_length=128, default='!')
    groups = models.ManyToManyField(
    user_permissions = models.ManyToManyField(

` ** What I've tried:**

  1. Flushing and starting new DB (as I used in-built Django user model before and some old users weren't fairing well with the new user-type field).
  2. Adding the user type with default employer option to employer view and fetching the usertype from user model.

** What I expect:** The profile view to connect with the custom user model and allow the user to add additional information to their user profile. And ofcourse the profile page to have the user-type attribute as initially stored from user class.

You probably import User not from your models file, but from django. Anyway I highly recommend (if you overwrote AUTH_USER_MODEL) using built-in get_user_model() method from Django e.g.:

from django.contrib.auth import get_user_model

def employer_profile_view(request, username):
    user = get_user_model().objects.get(username=username)
    if user.user_type != User.EMPLOYER:

And don't use User name for model, I prefer to use CustomUser by myself but you can name it differently, just to avoid mistakes.

Back to Top