寻找一个m2m的关系

时间:2011-05-18 14:57:50

标签: python django filter

鉴于下面的模型,我如何才能找到“天”字段今天拥有的对象。基本上,告诉我有特定日期的工作。比如'周三'。

非常感谢任何帮助。

model.py

class Day(models.Model):
    day = models.CharField(max_length=3)
    def __unicode__(self):
        return "%s"%(self.day)

class Job(models.Model):
    name = models.CharField(max_length=32, unique=True)
    ...
    start = models.TimeField()
    end = models.TimeField()
    days = models.ManyToManyField(Day)

view.py

today = datetime.date.today()
dayofweek = today.strftime("%a")
DAY = Day.objects.get(day=dayofweek)

#not sure how i would 'filter' this to get the results i need

1 个答案:

答案 0 :(得分:2)

Job.objects.filter(days=DAY)是正确的。