On Tue, Apr 27, 2010 at 9:50 AM, Florian Le Goff <bletofar...@gmail.com> wrote: > Hi, > > I'm using Django's 1.1.1 official release and I'm trying to build a > partial form, using ModelForm, with only one field, of the > ManyToManyField type. > > If my partial form's Meta class "fields" attribute contains several > attributes names, everything is working pretty smoothly. My form is > produced, the template rendering is allright, and I'm able to fetch > the values and save them using this partial form and request.POST . > > Unfortunately, if I try to set the field attribute of my partial form > to only one attribute (the ManyToManyField previously mentioned), I'm > getting an empty form. > > I'm calling my class this way : > > item = get_object_or_404(ItemChild, pk=item_id,) > form_item_select = ItemPartialParent(instance=item) > > And here is my model : > > class ItemChild(models.Model): > name = models.CharField(max_length=120) > > def __unicode__(self): > return self.name > > class ItemParent(models.Model): > name = models.CharField(max_length=120) > children = models.ManyToManyField(ItemChild) > > class ItemPartialParent(ModelForm): > class Meta: > model = ItemParent > # working ok : > # fields = ('children' , 'name') > # a call to ItemPartialParent() returns nothing : > fields = ('children') >
You're missing a comma here: Meta.fields is defined as an iterable. iter( ('children') ) will return each char in 'children' iter( ('children', ) ) will return 'children' >>> for a in ('children'): print a ... c h i l d r e n >>> for a in iter(('children',)): print a ... children Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.