hi,

More newbie questions. I have something similar to:

class BlogPost:
        [...]

class Comment:
        [...]
        blog_post = models.ForeignKey(BlogPost)


Now, when POSTing a comment, I have to set the 'blog' of the comment to 
the right blog item.


Right now I do:

def post_comment(request, blog_id):
        [snip]

        blog_post = BlogPost.objects.get(id__exact=blog_id) # from URL

        # If data was POSTed, we're trying to create a new Comment.
         new_data = request.POST.copy()

         # load up the blog id
         new_data['blog_post'] = blog_id

         # Check for errors.
         errors = manipulator.get_validation_errors(new_data)

         if not errors:
             # No errors. This means we can save the data!
             manipulator.do_html2python(new_data)
             new_comment = manipulator.save(new_data)

        [snip]

But this seems a bit dodgy as there is a blog.comment_set.add(..) 
function. I.e. how can I nicely tell the object that "blog_post" is it's 
parent? How do I join what the manipulator does and the way add( ) works 
without calling save twice?

I could do:

new_comment = manipulator.save(new_data)
new_comment.blog_post = blog_post
new_commet.save()

Which looks nicer, but saves twice.



  - bram

-- 
MTG                   - http://www.mtg.upf.edu/
The Freesound Project - http://freesound.iua.upf.edu
Smartelectronix       - http://www.smartelectronix.com
Musicdsp              - http://www.musicdsp.org
Office Telephone      - +34 935 422 101

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to