장고에 작은 캘린더 응용 프로그램을 만들고 있습니다. 두 개의 모델 클래스가 있습니다. 일정 및 이벤트. 이벤트는 여러 개의 캘린더에있을 수 있습니다. 이 때문에 ManyToMany 관계를 사용하고 있습니다.ManyToMany 관계의 쿼리 집합
이 내 모델입니다
from django.db import models
class Calendar(models.Model):
title = models.CharField(max_length = 255)
def __unicode__(self):
return self.title
class Event(models.Model):
title = models.CharField(max_length = 255)
start_date = models.DateField()
end_date = models.DateField(blank = True, null = True)
location = models.CharField(blank = True, max_length = 255)
description = models.TextField(blank = True)
important = models.BooleanField(default = False)
calendar = models.ManyToManyField(Calendar)
가 어떻게 특정 캘린더의 모든 이벤트와의 검색어를받을 수 있나요?
= '는'ManyToManyField'에 events'', shouldn 'my_calendar.event_set.all()'을 읽지 않았습니까? – Arnaud