On Jan 5, 3:27 am, GoSantoni <mj.schuur...@gmail.com> wrote: > Hey Daniel, > > Thanks for response, as always helpful and quick. Like you suggested I > changed the fields to the class. This resulted in a error because > BlogForm could not be found. So I decided not to bother the photologue > model but import the Images into the blog model. This resulted in: > > ***** blog models.py ********** > from photos.models import Image, Pool > .... > class blog(models.Model) > .... > class Post(models.Model): > blog = models.ForeignKey(blog) > item = models.CharField(_('item'), max_length=200) > imagepost = models.ManyToManyField(Image, blank=True, > verbose_name=_('post')) > > ***** blog forms.py ********** > 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."), > imagepost = forms.ModelMultipleChoiceField > (queryset=Image.objects.all()) > > def __init__(self, user=None, *args, **kwargs): > self.user = user > super(BlogForm, self).__init__(*args, **kwargs) > self.fields["imagepost"].queryset = Image.objects.all() > > class Meta: > > model = Post > exclude = ('author', 'creator_ip', 'created_at', 'updated_at', > 'publish') > **** > > This resolves is in a AttributeError 'module' object has no attribute > 'objects'. This is strange because the photos view uses a similar > queryset: photos = Image.objects.filter(member=request.user) Again i > just like to render the titles/urls of the images to attach them to > the posts. > > Cheers
You don't show how you're importing Image in the blog forms.py - it looks like you're importing the entire module under the name Image, rather than the actual Image model. Also note that you no longer need the __init__ method in BlogForm, since you do all the declarations at the class level and you don't need to override anything. -- 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.