this initial can be a queryset or a list, but the list must use its
primary key like sform = SymptomeForm(initial={'parent':[1,2]})

On 9月7日, 上午4时30分, Thomas49 <[email protected]> wrote:
> Hello,
>
> I have two models, and the second contains a ManyToMany relationship:
>
> class TypeMedical(models.Model):
>    ...
>
> class Symptome(TypeMedical):
>     ...
>     parent =
> models.ManyToManyField(TypeMedical,related_name='Parent',blank=True)
>     ...
>
> Then, I use a ModelForm in order to save data.
>
> class SymptomeForm(ModelForm):
>     class Meta:
>         model = Symptome
>
> When I create a form, sometimes I want to select a field in "parent".
> How can I do that? I tried many things but nothing works. Ex:
> sform = SymptomeForm(initial={'parent':["Acupuncture",]})
>
> I hope someone can help! Thanks,
>
> Thomas.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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