0

Here's my model,

class Question(models.Model):
    ...
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

How can I filter out the Questions asked in last 14 hours?

Thank You :)

1 Answers1

3
from datetime import datetime, timedelta

time_threshold = datetime.now() - timedelta(hours=14)
results = Question.objects.filter(timestamp__lt=time_threshold)

by docs __lt means less than.

Brown Bear
  • 19,655
  • 10
  • 58
  • 76
lapinkoira
  • 8,320
  • 9
  • 51
  • 94