Message info
 
To:Django users From:akaariai Subject:Re: registration forms.py Date:Sun, 19 Feb 2012 13:11:17 -0800 (PST)
 

On Feb 19, 1:42pm, Stanwin Siow <stanwin.kts...@gmail.com> wrote:
> Hello,
>
> The below method is an excerpt taken from the default registration forms.py with a few additional inputs.
>
> class RegistrationForm(forms.Form):
>
> keywords = forms.ModelMultipleChoiceField(queryset=Keyword.objects.all())
>
> def save(self, profile_callback=None):
>
> new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],password=self.cleaned_data['password1'],email=self.cleaned_data['email'],profile_callback=profile_callback)
> new_profile = UserProfile(user=new_user,username=self.cleaned_data['username'], keywords_subscribed=self.cleaned_data['keywords'],first_name=self.cleaned_data['first_name'],last_name=self.cleaned_data['last_name'],email=self.cleaned_data['email'])
> new_profile.save()
> return new_user
>
> The highlighted portions will draw your attention to what i'm doing. As you can see i'm using a modelmultiplechoicefield which allows me to select multiple choices.
>
> However when it gets stored into the database, it appends strange characters ( [<Keyword:)
>
> Is there a way to get rid of the special characters? or how is it even appearing or getting populated?

If keywords_subscribed is a character field (as it seems), you should
store something like [keyword.text for keyword in
self.cleaned_data['keywords']] in the field, not the model list
directly. Another option is to store the keywords in a
ManyToManyField. In any case, the problem seems to be the mismatch of
saving models instances into a field that doesn't expect model
instances.

- Anssi

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.