鉴于下面的模型,我如何才能找到“天”字段今天拥有的对象。基本上,告诉我有特定日期的工作。比如'周三'。
非常感谢任何帮助。
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
答案 0 :(得分:2)
Job.objects.filter(days=DAY)
是正确的。