On Thu, Nov 12, 2009 at 8:07 AM, EmileZola <marc....@gmail.com> wrote:
> Alright, I'm pretty new to Django and I've got this problem I can't > quite solve. > > I basically have two models, wich I use to put blog articles into > categories. One is a Category and the other is a Subject. So in my > categories I might have ('Programming', 'Music', 'Essays') and my > subjects are listed under those various categories. So under > Programming I might have ('Python', 'PHP', 'ASM'). > > Here a stripped down version of my models : > > class Category(models.Model): > name = models.CharField(_('Categorie'), max_length=100) > > class Subject(models.Model): > name = models.CharField(_('Forum'), max_length=100) > description = models.CharField(_('Description'), max_length=250) > category = models.ForeignKey(Category) > > Now, what I try to do in my view, is to loop through the categories > and list each subject it contains. Someone can help me ? > for category in Category.objects.all(): print category for subject in category.subject_set.all(): print subject -- 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=.