This is my model:
这是我的模特:
class People(models.Model):
Name = models.CharField(max_length=100)
Lastname = models.CharField(max_length=100)
Record_Date=models.DateTimeField()
In views.py
"""Takes an integer value representing the day of week from 1 (Sunday) to 7 (Saturday)."""
People.objects.filter(Record_Date__week_day=1)
It gives me all Sunday Record_Date's. That is fine. But, I want to get a more specific hour inside each Sunday data. For example, Every Sunday 10:30-11:55. How can I do that with using query or What is other alternatives to do that?
它给了我所有的Sunday Record_Date。没事儿。但是,我想在每个星期日数据中获得更具体的时间。例如,每周日10:30-11:55。如何使用查询或其他替代方法来做到这一点?
1
You can always just take the results out and filter in python.
你总是可以把结果拿出来并在python中过滤。
results = People.objects.filter(Record_Date__week_day=1)
filtered = [r for r in results if 55 <= r.Record_Date.minute <= 30 and 10 <= r.Record_Date.hour <= 11]
And split out into a loop for easier debug:
并分成一个循环以便于调试:
results = People.objects.filter(Record_Date__week_day=1)
filtered = []
for r in results:
print r.Record_Date
if 55 <= r.Record_Date.minute <= 30:
print r.Record_Date.minute, r.Record_Date.hour
if 10 <= r.Record_Date.hour <= 11:
print "Found!"
filtered.append(r)
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/10/17/44fede578152a07124ca83fd59221486.html。