Django DateTimeField to compare with datetime.now ()

I have DateTimeField:

class Assignment (models.Model):
   official_deadline = models.DateTimeField(null=True, blank=True)

I need to compare it with the current time, I tried:

def official_deadline_past(self):
    if datetime.datetime.today() > self.official_deadline:
        return True
    return False

But he always comes back. FalseI also tried:

def official_deadline_past(self):
    if datetime.datetime.now() > self.official_deadline:
        return True
    return False

But I have the same problem.

I have information in the field: 2011-07-02 00:00:00for example, in the form generatedModelForm

+5
source share
1 answer

I had a similar problem comparing DateTimeField with datetime in python 2.7.3 and django 1.3.1

I do not think DateTimeField had good time zone support, or I did not configure it correctly.

Whenever I specified the time zone for the datetime field, all my DateTimeField> datetime comparisons did not work.

datetime , DateTimeField .

, timedelta (hours = 1) datetime, "" .

0

All Articles