Yep. I used Firebug to look at the HTTP information and "username" is in there. Here's what firebug shows:
Parametersapplication/x-www-form-urlencoded address P.O. Box 56868 areas 1 birth_date 1979-10-09 city Puyallup country USA csrfmiddlewaretoken 0258a209df8a7df0ccca24ce789a448e email someem...@hotmail.com first_name Toby last_name Beal password1 1234 password2 1234 phone 253-555-555 state_province WA username tobybeal zip_code 98379 I believe that the problem isn't with the form creation or submission but with my save method. The error seems to be specific to the way in which I'm trying to create a new user. Here's my save method from the form again. # Taken from registration.forms.py def save(self): # User new_user = User.objects.create_user(username=self.cleaned_data['username'], email=self.cleaned_data['email'], password=self.cleaned_data['password1']) new_user.first_name = self.cleaned_data['first_name'] new_user.last_name = self.cleaned_data['last_name'] new_user.is_active = True new_user.save() # Profile new_profile = UserProfile.objects.create() new_profile.user = User.objects.get(username__exact=self.cleaned_data['username']) new_profile.phone = self.cleaned_data['phone'] new_profile.address = self.cleaned_data['address'] new_profile.city = self.cleaned_data['city'] new_profile.state_province = self.cleaned_data['state_province'] new_profile.country = self.cleaned_data['country'] new_profile.zip_code = self.cleaned_data['zip_code'] new_profile.birth_date = self.cleaned_data['birth_date'] new_profile.areas = self.cleaned_data['areas'] new_profile.save() return What should I be doing differently with this snippet? new_user = User.objects.create_user(username=self.cleaned_data['username'], email=self.cleaned_data['email'], password=self.cleaned_data['password1']) Thanks. ~trb On Aug 5, 4:32 am, Paulo Almeida <igcbioinformat...@gmail.com> wrote: > Can you check the POST data and see if 'username' is there? You can do it > easily with Firefox's Firebug extension. > > - Paulo > > On Thu, Aug 5, 2010 at 6:24 AM, strayhand <tobyb...@gmail.com> wrote: > > So I'm rolling out my own registration form that should update the > > following models: > > > - User (auth module) > > - UserProfile > > > Everything seems to be coming together but I'm having a hard time with > > the save() method for the form. My UserProfile model has a couple of > > fields that refer to other models and I'm having difficulty setting > > them up properly. I keep getting an error telling me: > > > Exception Type: IntegrityError at /registration/ > > Exception Value: auth_user.username may not be NULL > > > I know where the problems are: > > > new_user = > > User.objects.create_user(username=self.cleaned_data['username'], > > email=self.cleaned_data['email'], > > password=self.cleaned_data['password1']) > > > and I'm getting this similar error for defining the user profile on > > the line below. > > > new_profile.user = > > User.objects.get(username__exact=self.cleaned_data['username']) > > > I'm just not sure how else to write this stuff. I'm including my form, > > model and the exact error message that I'm getting below. Any insight > > that you have is greatly appreciated. Thank you. > > > # registration.forms.py > > > import re > > from django import forms > > from django.db import models > > from django.contrib.localflavor.us.forms import USPhoneNumberField > > from django.contrib.auth.models import User > > from ylbbq.areas.models import Area > > from ylbbq.profiles.models import UserProfile > > > STATES = ( > > ('WA', 'Washington'), > > ('AK', 'Alaska'), > > ('AL', 'Alabama'), > > ('AR', 'Arkansas'), > > ('AZ', 'Arizona'), > > ('CA', 'California'), > > ('CO', 'Colorado'), > > ('CT', 'Connecticut'), > > ('DE', 'Delaware'), > > ('FL', 'Florida'), > > ('GA', 'Georgia'), > > ('HI', 'Hawaii'), > > ('IA', 'Iowa'), > > ('ID', 'Idaho'), > > ('IL', 'Illinois'), > > ('IN', 'Indiana'), > > ('KS', 'Kansas'), > > ('KY', 'Kentucky'), > > ('LA', 'Louisiana'), > > ('MA', 'Massachusetts'), > > ('MD', 'Maryland'), > > ('ME', 'Maine'), > > ('MI', 'Michigan'), > > ('MN', 'Minnesota'), > > ('MO', 'Missouri'), > > ('MS', 'Mississippi'), > > ('MT', 'Montana'), > > ('NC', 'North Carolina'), > > ('ND', 'North Dakota'), > > ('NE', 'Nebraska'), > > ('NH', 'New Hampshire'), > > ('NJ', 'New Jersey'), > > ('NM', 'New Mexico'), > > ('NV', 'Nevada'), > > ('NY', 'New York'), > > ('OH', 'Ohio'), > > ('OK', 'Oklahoma'), > > ('OR', 'Oregon'), > > ('PA', 'Pennsylvania'), > > ('RI', 'Rhode Island'), > > ('SC', 'South Carolina'), > > ('SD', 'South Dakota'), > > ('TN', 'Tennessee'), > > ('TX', 'Texas'), > > ('UT', 'Utah'), > > ('VT', 'Vermont'), > > ('VA', 'Virginia'), > > ('WI', 'Wisconsin'), > > ('WV', 'West Virginia'), > > ('WY', 'Wyoming'), > > ('AB', 'Alberta'), > > ('BC', 'British Columbia'), > > ('MB', 'Manitoba'), > > ('NB', 'New Brunswick'), > > ('NL', 'Newfoundland and Labrador'), > > ('NS', 'Nova Scotia'), > > ('NT', 'Northwest Territories'), > > ('NU', 'Nunavut'), > > ('ON', 'Ontario'), > > ('PE', 'Prince Edward Island'), > > ('QC', 'Quebec'), > > ('SK', 'Saskatchewan'), > > ('YT', 'Yukon'), > > ) > > > COUNTRIES = ( > > ('USA', 'United States'), > > ('Canada', 'Canada') > > ) > > > POSTAL_CODE_PATTERN = re.compile(r'^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z] > > \d[A-Z]\d$') > > > class RegisterForm(forms.Form): > > username = forms.CharField(max_length=30, help_text='Create a user > > name for this Web site.') > > first_name = forms.CharField(max_length=30) > > last_name = forms.CharField(max_length=30) > > password1 = forms.CharField(max_length=60, label='Password', > > widget=forms.PasswordInput) > > password2 = forms.CharField(max_length=60, label='Password > > Confirmation', widget=forms.PasswordInput) > > email = forms.EmailField(help_text='Enter a valid e-mail address.') > > phone = USPhoneNumberField(max_length=12, help_text='Enter your > > phone > > number in the following format: 253-123-5678.') > > address = forms.CharField(max_length=70, help_text='Enter mailing > > address.') > > city = forms.CharField(max_length=50) > > state_province = forms.ChoiceField(choices=STATES, label='State or > > Province') > > country = forms.ChoiceField(choices=COUNTRIES) > > zip_code = forms.CharField(max_length=10, label='Mailing Code', > > help_text='Enter your zip code (US or Canadian).') > > birth_date = forms.DateField(help_text='Enter your birthdate in the > > following format: 1979-09-29 (YYYY-MM-DD).') > > areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(), > > label='Preferred Areas', help_text='Select the areas that you\'d like > > to serve.') > > > def clean_username(self): > > data = self.cleaned_data['username'] > > try: > > User.objects.get(username=data) > > except User.DoesNotExist: > > return > > raise forms.ValidationError('The username "%s" is already > > taken.' % > > data) > > > def clean_zip_code(self): > > data = self.cleaned_data['zip_code'] > > match_code = POSTAL_CODE_PATTERN.match(data) > > if match_code is None: > > raise forms.ValidationError('Enter a valid US or > > Canadian zip > > code.') > > return > > > def clean(self): > > data = self.cleaned_data > > > # Compare the two passwords for a match > > pw1 = data.get('password1') > > pw2 = data.get('password2') > > > if pw1 != pw2: > > msg = "Passwords do not match" > > self._errors['password2'] = self.error_class([msg]) > > > return data > > > def save(self): > > > # User > > new_user = > > User.objects.create_user(username=self.cleaned_data['username'], > > email=self.cleaned_data['email'], > > password=self.cleaned_data['password1']) > > new_user.first_name = self.cleaned_data['first_name'] > > new_user.last_name = self.cleaned_data['last_name'] > > new_user.is_active = True > > new_user.save() > > > # Profile > > new_profile = UserProfile.objects.create() > > new_profile.user = > > User.objects.get(username__exact=self.cleaned_data['username']) > > new_profile.phone = self.cleaned_data['phone'] > > new_profile.address = self.cleaned_data['address'] > > new_profile.city = self.cleaned_data['city'] > > new_profile.state_province = > > self.cleaned_data['state_province'] > > new_profile.country = self.cleaned_data['country'] > > new_profile.zip_code = self.cleaned_data['zip_code'] > > new_profile.birth_date = self.cleaned_data['birth_date'] > > new_profile.areas = self.cleaned_data['areas'] > > new_profile.save() > > > return > > > # profiles.models.py > > > from django.db import models > > from django.contrib.auth.models import User > > from ylbbq.areas.models import Area > > > STATES = ( > > ('AK', 'Alaska'), > > ('AL', 'Alabama'), > > ('AR', 'Arkansas'), > > ('AZ', 'Arizona'), > > ('CA', 'California'), > > ('CO', 'Colorado'), > > ('CT', 'Connecticut'), > > ('DE', 'Delaware'), > > ('FL', 'Florida'), > > ('GA', 'Georgia'), > > ('HI', 'Hawaii'), > > ('IA', 'Iowa'), > > ('ID', 'Idaho'), > > ('IL', 'Illinois'), > > ('IN', 'Indiana'), > > ('KS', 'Kansas'), > > ('KY', 'Kentucky'), > > ('LA', 'Louisiana'), > > ('MA', 'Massachusetts'), > > ('MD', 'Maryland'), > > ('ME', 'Maine'), > > ('MI', 'Michigan'), > > ('MN', 'Minnesota'), > > ('MO', 'Missouri'), > > ('MS', 'Mississippi'), > > ('MT', 'Montana'), > > ('NC', 'North Carolina'), > > ('ND', 'North Dakota'), > > ('NE', 'Nebraska'), > > ('NH', 'New Hampshire'), > > ('NJ', 'New Jersey'), > > ('NM', 'New Mexico'), > > ('NV', 'Nevada'), > > ('NY', 'New York'), > > ('OH', 'Ohio'), > > ('OK', 'Oklahoma'), > > ('OR', 'Oregon'), > > ('PA', 'Pennsylvania'), > > ('RI', 'Rhode Island'), > > ('SC', 'South Carolina'), > > ('SD', 'South Dakota'), > > ('TN', 'Tennessee'), > > ('TX', 'Texas'), > > ('UT', 'Utah'), > > ('VT', 'Vermont'), > > ('VA', 'Virginia'), > > ('WA', 'Washington'), > > ('WI', 'Wisconsin'), > > ('WV', 'West Virginia'), > > ('WY', 'Wyoming'), > > ('AB', 'Alberta'), > > ('BC', 'British Columbia'), > > ('MB', 'Manitoba'), > > ('NB', 'New Brunswick'), > > ('NL', 'Newfoundland and Labrador'), > > ('NS', 'Nova Scotia'), > > ('NT', 'Northwest Territories'), > > ('NU', 'Nunavut'), > > ('ON', 'Ontario'), > > ('PE', 'Prince Edward Island'), > > ('QC', 'Quebec'), > > ('SK', 'Saskatchewan'), > > ('YT', 'Yukon'), > > ) > > > COUNTRIES = ( > > ('USA', 'United States'), > > ('Canada', 'Canada') > > ) > > > # Create your models here. > > class UserProfile(models.Model): > > user = models.ForeignKey(User, unique=True) > > phone = models.CharField(max_length=12) > > address = models.CharField(max_length=70) > > city = models.CharField(max_length=50) > > state_province = models.CharField(max_length=2, choices=STATES, > > verbose_name='State or Province') > > country = models.CharField(max_length=20, choices=COUNTRIES) > > zip_code = models.CharField(max_length=7) > > birth_date = > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.