Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 604721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:04:08+00:00 2026-05-13T17:04:08+00:00

So im wanting to extend the django auth.User model to add extra fields. Ive

  • 0

So im wanting to extend the django auth.User model to add extra fields. Ive read a few articles here and there, and am almost there.

Im just trying to make the signup form at the moment. So a new user can sign up. I can get the new User created but when I come to save the UserProfile object to the database it fails citing

Cannot assign "u'clare'": "Customer.user" must be a "User" instance.

where “clare” is the username ive put in. This user is created in Auth.User, but the UserProfile, in this case called Customer is not created. So I think im doing something wrong when creating the object and using the foreign key to do so. Anyway below are the relevant files.

models.py

from django.db import models
from RadioBusiSite.music.models import PlayList
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django import forms

class Location(models.Model):
    Address = models.CharField(max_length=300)
    PhoneNumber = models.CharField(max_length=15)
    Size = models.IntegerField('Size of Premises')

    def __unicode__(self):
        return self.Address

class Customer(models.Model):
    user = models.ForeignKey(User, unique=True)
    Company = models.CharField(max_length=200)
    ContactPerson = models.CharField('Contact Person', max_length=200)
    email = models.CharField(max_length=200)
    ABN = models.CharField(max_length=50)
    Location = models.ForeignKey(Location)
    Playlist = models.ManyToManyField(PlayList)

    def __unicode__(self):
        return self.Company

forms.py

from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django import forms
from RadioBusiSite.customer.models import Customer
from django.forms.models import modelformset_factory

class CustomerForm(forms.Form):
    user = forms.CharField(max_length=30, label='User Name')
    password1 = forms.CharField(max_length=30, label='Password', widget=forms.PasswordInput(render_value=False))
    password2 = forms.CharField(max_length=30, label=' Check Password', widget=forms.PasswordInput(render_value=False))
    Company = forms.CharField(max_length=200)
    ContactPerson = forms.CharField(max_length=200)
    email = forms.EmailField()
    ABN = forms.CharField(max_length=50)
    #Location = forms.ForeignKey(Location)
    #Playlist = forms.ManyToManyField(PlayList)

    def clean(self):
        if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password1'] != self.cleaned_data['password2']:
                raise forms.ValidationError("You must type the same password each time")
        return self.cleaned_data

    def clean_user(self):
        try:
            User.objects.get(username=self.cleaned_data['user'])
        except User.DoesNotExist:
            return self.cleaned_data['user']
        raise forms.ValidationError("This user is already in use. Please Choose another one.")

    def save(self):
        new_user = User.objects.create_user(username = self.cleaned_data['user'],
                                            email = self.cleaned_data['email'],
                                            password = self.cleaned_data['password1'])
        new_customer = Customer.objects.create(user=self.cleaned_data['user'],
                                               company = self.cleaned_data['Company'],
                                               ContactPerson = self.cleaned_data['ContactPerson'],
                                               email = self.cleaned_data['email'],
                                               ABN = self.cleaned_data['ABN'])

views.py

from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from RadioBusiSite.customer.models import Customer,Location
from RadioBusiSite.customer.forms import CustomerForm
from django.contrib.auth import authenticate
from django.contrib.auth.models import User

def addCustomer(request):
    if request.method == 'POST':
        #user = UserForm(request.POST, instance=request.user)
        form = CustomerForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/home/')
    else:
        form = CustomerForm()

    return render_to_response('addCustomer.html', {
        'form': form,
    })

And ive enabled the AUTH think like so

AUTH_PROFILE_MODULE = ‘customer.Customer’

the file above are all in a folder called “customer”

Any help would be great.

Cheers
Mark

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:04:09+00:00Added an answer on May 13, 2026 at 5:04 pm
    def save(self):
        new_user = User.objects.create_user(username = self.cleaned_data['user'],
                            email = self.cleaned_data['email'],
                            password = self.cleaned_data['password1'])
        new_customer = Customer.objects.create(user=**new_user**,
                               company = self.cleaned_data['Company'],
                               ContactPerson = self.cleaned_data['ContactPerson'],
                               email = self.cleaned_data['email'],
                               ABN = self.cleaned_data['ABN'])
    

    Notice the change **within stars** above. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.