Hi

Trying to use save_m2m as described here
http://docs.djangoproject.com/en/1.0/topics/forms/modelforms/#the-save-method
Though in run into an attrribute error 'Post' object has no attribute
'save_m2m'

*** Model ***
class Post(models.Model):
    id                     = models.AutoField(primary_key=True)
    imagepost       = models.ManyToManyField(Image, verbose_name=_
('media'))

    def save(self, force_insert=False, force_update=False):
        self.updated_at = datetime.now()
        super(Post, self).save(force_insert, force_update)

*** View ***
def new(request, form_class=BlogForm, template_name="blog/new.html"):
    if request.method == "POST":
        if request.POST["action"] == "create":
            blog_form = form_class(request.user, request.POST)
            if blog_form.is_valid():
                blog = blog_form.save(commit=False)
                blog.author = request.user
                if getattr(settings, 'BEHIND_PROXY', False):
                    blog.creator_ip = request.META
["HTTP_X_FORWARDED_FOR"]
                else:
                    blog.creator_ip = request.META['REMOTE_ADDR']
                blog.save()
                blog.save_m2m()
                request.user.message_set.create(message=_
("Successfully saved post '%s'") % blog.item)
                if notification:
                    if blog.status == 2: # published
                        if friends: # @@@ might be worth having a
shortcut for sending to all friends
                            notification.send((x['friend'] for x in
Friendship.objects.friends_for_user(blog.author)), "blog_friend_post",
{"post": blog})

                return HttpResponseRedirect(reverse
("blog_list_yours"))
        else:
            blog_form = form_class()
    else:
        blog_form = form_class(request.user)

    return render_to_response(template_name, {
        "blog_form": blog_form,

    }, context_instance=RequestContext(request))

Question 1:
So far i found these 2 posts using map and instances in the view. Is
that the way to solve this?
http://stackoverflow.com/questions/1477319/how-to-get-the-django-current-login-user
http://haineault.com/blog/101/

Question 2:
Does the def save() in the model need alteration? Or addition of a def
save_m2m() ? Change gives a 'super' object has no attribute 'save_m2m'

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