Hi,

I've been beating my head against this for a couple of days.  I am
creating a User with additional information stored in a profile
model.  I create the user, then create the profile object. I get the
form information and if it is valid, I just want to save the
information and do a bit more processing.

Two questions:
1. Why is the profile information not saving?
2. If I want to access the activation_string for a specific user and
change it's value, how do I do that?  I'm sure the way I'm trying to
do it is incorrect.

Any assistance would be appreciated.

Thanks,
Laura

**********I have this Model:

class StudentProfile(models.Model):
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    province = models.CharField(max_length=30)
    postalcode = models.CharField(max_length=50)
    telephone = models.CharField(max_length=12)
    memberoffice = models.ForeignKey('memberoffices.MemberOffice')
    creationdate = models.DateTimeField(auto_now_add=True)
    activated = models.BooleanField(default=False)
    activation_string = models.CharField(max_length=30, unique=True)
    activationdate = models.DateTimeField(null=True)
    user = models.ForeignKey(User,unique=True)

**********I have set it up in settings.py this way:
AUTH_PROFILE_MODULE = 'students.StudentProfile'


********** I have this form:
class StudentForm(forms.Form):
        username = forms.CharField(max_length=30)
        first_name = forms.CharField(max_length=30)
        last_name = forms.CharField(max_length=30)
        email = forms.EmailField()
        password1 =
forms.CharField(max_length=30,widget=forms.PasswordInput(render_value=False))
        password2 =
forms.CharField(max_length=30,widget=forms.PasswordInput(render_value=False))
        address = forms.CharField(max_length=50)
        city = forms.CharField(max_length=60)
        province = forms.CharField(max_length=30)
        postalcode = forms.CharField(max_length=50)
        telephone = forms.CharField(max_length=12)
        memberoffice =
forms.ModelMultipleChoiceField(queryset=MemberOffice.objects.all())

**********and this save routine associated with the form to save it:
        def save(self):

            newstudent =
User.objects.create_user(username=self.cleaned_data['username'],
 
email=self.cleaned_data['email'],
 
password=self.cleaned_data['password1'])
            newstudent.is_staff = False
            newstudent.first_name = self.cleaned_data['first_name']
            newstudent.last_name = self.cleaned_data['last_name']
            newstudent.save()
            try:
                newStudentProfile = request.newstudent.get_profile()
            except:
                newStudentProfile = StudentProfile(user=newstudent)
                newStudentProfile.address =
self.cleaned_data['address']
                newStudentProfile.city = self.cleaned_data['city']
                newStudentProfile.province =
self.cleaned_data['province']
                newStudentProfile.postalcode =
self.cleaned_data['postalcode']
                newStudentProfile.memberoffice =
MemberOffice(id=self.cleaned_data['memberoffice'])
                newStudentProfile.save()
            return newstudent

**********This is the controlling view.py file:

def registerstudent(request,language):
    if request.POST:
       form = StudentForm(data=request.POST)
       if form.is_valid():
            newstudent = form.save()
            newstudent.get_profile().activation_string =
generate_activation_string()
            email_content =
create_activation_email_content(newprofile.activation_string)
 
send_activation_email(newstudent.first_name,newstudent.email,email_content)
            return HttpResponse('You\'ll receive an email. Click the
link in the email.')
       else:
            errors = form.errors
            return HttpResponse(errors)
    else:
        form = StudentForm()
        return render_to_response('englishpublic/register.html',
{'form':form,})


**********This is the error/traceback:
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/english/register/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.flatpages',
 'django.contrib.admindocs',
 'endeavor.students',
 'endeavor.memberoffices',
 'endeavor.membermanagers',
 'endeavor.courses',
 'endeavor.courseproviders']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
in get_response
  86.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/Users/laurarey/LAR Studios/endeavor/../endeavor/students/
views.py" in registerstudent
  29.             newstudent = form.save()
File "/Users/laurarey/LAR Studios/endeavor/../endeavor/students/
forms.py" in save
  55.                 newStudentProfile.save()
File "/Library/Python/2.5/site-packages/django/db/models/base.py" in
save
  307.         self.save_base(force_insert=force_insert,
force_update=force_update)
File "/Library/Python/2.5/site-packages/django/db/models/base.py" in
save_base
  367.                 values = [(f, f.get_db_prep_save(raw and
getattr(self, f.attname) or f.pre_save(self, True))) for f in
meta.local_fields if not isinstance(f, AutoField)]
File "/Library/Python/2.5/site-packages/django/db/models/fields/
related.py" in get_db_prep_save
  665.             return
self.rel.get_related_field().get_db_prep_save(value)
File "/Library/Python/2.5/site-packages/django/db/models/fields/
__init__.py" in get_db_prep_save
  192.         return self.get_db_prep_value(value)
File "/Library/Python/2.5/site-packages/django/db/models/fields/
__init__.py" in get_db_prep_value
  353.         return int(value)

Exception Type: TypeError at /english/register/
Exception Value: int() argument must be a string or a number, not
'list'

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to