On Jan 3, 7:54 pm, GoSantoni <mj.schuur...@gmail.com> wrote: > Hi group, > > I've been using the django project docs about the ModelForm but still > I've got problems using the ModelMultipleChoiceField for a > ManyToManyField relation. The aim is to relate Images to blog Posts. > So images can get attached to multiple posts and posts can be attached > to multiple images. I'd like to use this relation to render the list > of Image titels in a the BlogForm to attach an image to a new post. > <snip apparently irrelevant model> > > ******************** forms.py in blog app for adding a new post > ********************* > class BlogForm(forms.ModelForm): > > slug = forms.SlugField(max_length=20, > help_text = _("a short version of the title consisting only of > letters, numbers, underscores and hyphens."), > error_message = _("This value must contain only letters, > numbers, underscores and hyphens.")) > > class Meta: > > model = Post > exclude = ('author', 'creator_ip', 'created_at', 'updated_at', > 'publish') > imagepost = forms.ModelMultipleChoiceField > (queryset=ImageModel.objects.all()) > > def __init__(self, user=None, *args, **kwargs): > self.user = user > super(BlogForm, self).__init__(*args, **kwargs) > self.fields["imagepost"].queryset = ImageModel.objects.all() > > Despite the existence of images it keeps on running in a KeyError. It > fails to render the titles.. > Anybody ideas? > Thanks
Why have you put the 'imagepost' declaration under Meta, when all the other field declarations are at the class level? They should all be at the class level. -- DR. -- 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.