I have a question in Django on how you can compare dates to solve some solutions. For example I have a datefield in my models.py Like below.
class Invoice(models
Use datetime.now()
(notice the parens). Other than that, remember that the field will always be a datetime
object. Also, (I guess that) you should check only the date of the datetime to match the current date (or else it will only match that specific second). For that you have to check if payment_date.date() == date.today()
(where date
is datetime.date
)
This also means that you can filter like this: Invoice.objects.filter(payment_date__lte=datetime.now())
.
__lte
, __gte
, __lt
, __gt
are used for <=
, >=
, <
and >