Monday, February 28, 2011

multi model forms

hi guys
I am new to django.

I have got two model User(Django built in ) and a model customer, user
is foreign key in customer

class Customer(models.Model):
user = models.ForeignKey(User, related_name='customers')
street = models.CharField(max_length=200)
city = models.CharField(max_length=100)
postal_code = models.IntegerField()
country = models.CharField(max_length=70)

i have written a view as below

def userForm(request):

if request.method == 'POST':
userform = UserForm(request.POST)
customerform = CustomerForm(request.POST)
if userform.is_valid() and customerform.is_valid():

u =
customer = Customer()
customer.user = u
return HttpResponseRedirect('/webshop/')

userform = UserForm()
customerform = CustomerForm()
context = RequestContext(request, {'userform':userform,
return render_to_response('userRegister.html', context)

but i get an erro saying xception Type: IntegrityError
Exception Value:

mainsiteapp_customer.lastname may not be NULL

please if anyonw can help

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment