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.

*********************** photologue models.py with the imagepost field
****************
class Image(ImageModel):
    """
    A photo with its details
    """
    SAFETY_LEVEL = (
        (1, _('Safe')),
        (2, _('Not Safe')),
    )
    title = models.CharField(_('title'), max_length=200)
    title_slug = models.SlugField(_('slug'))
    caption = models.TextField(_('caption'), blank=True)
    date_added = models.DateTimeField(_('date added'),
default=datetime.now, editable=False)
    is_public = models.BooleanField(_('is public'), default=True,
help_text=_('Public photographs will be displayed in the default
views.'))
    member = models.ForeignKey(User, related_name="added_photos",
blank=True, null=True)
    safetylevel = models.IntegerField(_('safetylevel'),
choices=SAFETY_LEVEL, default=1)
    photoset = models.ManyToManyField(PhotoSet, blank=True,
verbose_name=_('photo set'))
    tags = TagField()
    imagepost = models.ManyToManyField(BlogForm, blank=True,
verbose_name=_('post'))

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

--

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.


Reply via email to