I'm brand new to Django, so the answer to this is probably very simple. However, I can't figure it out.
Say I have two bare-bones Models.
class Blog(models.Model):
title = models.CharField(max_length=160)
text = models.TextField()
class Comment(models.Model):
blog = models.ForeignKey(Blog)
text = models.TextField()
In the Python/Django shell, if I have a Blog object in a variable (say blog = Blog.objects.get(id=3)
), how do I select all its child comments?
This doesn't seem to work: blog.objects.all()
to follow foreign keys 'backwards' you use
blog.comment_set.all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With