On Mon, Jul 20, 2009 at 23:24, AKK <[email protected]> wrote:
>
> Hello, i currently have two classes in my model:
>
> class Post(models.Model):
> prepopulated_fields = {"post_slug": ("post_title",)}
>
> post_title = models.CharField(max_length=750)
> post_slug = models.SlugField()
> ........................
>
> def __unicode__(self):
> return self.post_title
>
>
> class Comment(models.Model):
> comment_post = models.ForeignKey('Post')
> comment_date = models.DateTimeField('Date comment made')
> comment_body = models.TextField()
> comment_spam = models.BooleanField(default=False)
> comment_author = models.CharField(max_length=5000)
>
> def __unicode__(self):
> return unicode(self.comment_post)
>
>
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> And i want a view that returns the post and all the related comments.
> This is what i have:
>
> def title_view(request, slug):
> blog_posts = Post.objects.filter(post_slug=slug)
> blog_comments = Comment.objects.filter(some filter)
> return render_to_response('blogSite/comments.html', locals(),
> context_instance=RequestContext(request))
You can access a posts comments through blog_posts.comment_set
Also see:
http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---