0

My question is:

Using the following query how can I get contacts that are due now()? ie all contacts at the time of running the view that have not been sent

Contact.objects.filter(send_email_on=<WHERE TIME NOW???? , status='not sent')

Note I don't want future contacts juts ones not send up to now()

4

2 回答 2

2

Well, you may try with:

from datetime import datetime
# greater than or equal now(), change the __lte for whatever you need
Contact.objects.filter(send_email_on__lte=datetime.now(), status='not sent')

You can take a look at the docs which is very helpful with Field lookups strings.

HINT:

  1. __lt lower than
  2. __lte lower than or equal
  3. __gt greater than
  4. __gte greater than or equal
于 2013-05-30T13:16:37.830 回答
1
import datetime
from django.utils.timezone import utc

now = datetime.datetime.utcnow().replace(tzinfo=utc)    
Contact.objects.filter(send_email_on__lt=now , status='not sent')

Provided that send_email_on is a DateTimeField. For the lt(less than) see here.

Though I think you need to use celery and periodic tasks.

于 2013-05-30T13:13:48.067 回答