Hey Nikhil,
I might be wrong but please check your UserProfile model

   - In your __Unicode(something) function check for syntax error. i think 
   it should be __Unicode__
   - And why are you trying to return full name of User. I think you should 
   return self.user there so that when you are requesting back you can get 
   User Object back

If these answers are wrong and feels like bullshit then pls ignore... I am 
also trying to learn:)
Thanks,

On Monday, July 2, 2012 6:47:03 PM UTC+5:30, Nikhil Verma wrote:
>
> HI All
>
> I am applying an django-registration in my app. So i create a UserProfile 
> Model and  a ModelForm after clicking on the email link
> the user is redirected to the ModelForm page of UserProfile. I am filling 
> the details and trying to save it, however i am getting the above error.
>
>
> Traceback:-
>
>
> Exception Type: ValueError at /myprofile/completingprofile/
> Exception Value: Cannot assign "<django.utils.functional.SimpleLazyObject 
> object at 0x3487c10>": "UserProfile.user" must be a "User" instance.
>
>
> model
>
> class UserProfile(models.Model):
>     user = models.ForeignKey(User, blank=True, null=True, unique=True)
>     first_name = models.CharField(max_length=30)
>     last_name = models.CharField(max_length=30, blank=True)
>     gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
>     mobile = models.CharField(max_length=15, blank=True)
>     primary_email = models.EmailField(max_length=60, blank=True)
>
>     # For professional Account
>     institution_name = 
> models.CharField(max_length=100,blank=True,null=True)
>    
>     street = models.CharField(max_length=75)
>     state = models.CharField(max_length=30)
>     zip_code = models.IntegerField(max_length=7, blank=True, null=True)
>     country = models.CharField(max_length=30, blank=True)
>     
>        
>     def __unicode(self):
>         name = self.first_name + self.last_name
>         return name
>
>
> form.py
>
> class UserProfileForm(ModelForm):
>     class Meta:
>         model = UserProfile
>         exclude = ('user',)
>         
>     def __init__(self, *args, **kwargs):
>         super(UserProfileForm, self).__init__(*args, **kwargs)
>
>
>
> views.py 
>
> def completingprofile(request):
>     """
>     Creating Profile
>     """
>     print request
>     if request.method == "POST":
>         
>         form = UserProfileForm(request.POST)
>         if form.is_valid():
>             userprofile_obj = UserProfile(    
>                 first_name = form.cleaned_data['first_name'],
>                 last_name = 
> form.cleaned_data['last_name'],                                
>                 gender = form.cleaned_data['gender'],
>                 mobile = form.cleaned_data['mobile'],
>                 institution_name = form.cleaned_data['institution_name'],
>                 street = form.cleaned_data['street'],
>                 zip_code = form.cleaned_data['zip_code'],
>                 state = form.cleaned_data['state'],
>                 country = form.cleaned_data['country'],
>                 user = request.user,# here i am trying to add user from 
> request who is coming from RegistrationForm from django -registration
>                # I am getting the error in this above line  
>             )
>             userprofile_obj.save()
>             logger.info("Save profile for user: %s" % request.user)
>             
>             return HttpResponseRedirect('/thanks/')
>     else:
>         form = UserProfileForm()
>     return render_to_response("myprofile/profile_page.html", 
>         {"form": form },
>         context_instance=RequestContext(request)
>         )    
>  
> How can i save the user field ?
>
>
> Thanks for help in advance
>
> -- 
> Regards
> Nikhil Verma
> +91-958-273-3156
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12436236-8cee-4ce0-bd71-e15fe1b730d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to