Thursday, July 28, 2011

Transform model field to custom form field when creating from instance

Hi,

I created a PostForm, ModelForm for Post model that has a ManyToMany
relationship with a model called Test, I use a CharField and a
clean_test(): to convert the comma separated list of test names to a
list of Test objects and this works perfectly.

Now, when I want to use the PostForm for editing a Post I want the
CharField to display a comma separated list of test names from the
ManyToMany field. I can't find where in my PostForm I could hookup to
fill up the CharField when I do PostForm(instance=instance) to get my
ManToMany converted to a list of names.

Apart from that, is it good manners to access and create other Model
objects from ModelForms? like in clean_ methods?

Thanks

Arkaitz

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate