python - Subtract datetime in Django - no output -


i want "age" of user account in django app. did:

class userdata(models.model):     user = models.foreignkey(user,unique=true)     birth = models.integerfield(default=1900)     gender = models.charfield(max_length=1)      @property     def isnew(self):         if (datetime.datetime.now()-self.user.date_joined) < datetime.timedelta(days=40):             return true;         else:             return false; 

in template there different view depending on output of function. there no output.

when "printing" output there nothing returned. when returning "datetime" , "date_joined" date shown. when returning str(type()) of both "datetime.datetime" returned. when returning difference (or type of difference) there absolutely nothing returned. when doing same in python console there timedelta returned - expect.

any idea search next? can't figure out what's happening prevent function giving output without crashing app.

you trying substract offset-naive , offset-aware datetimes.

you need install pytz pip install pytz , change method following:

import datetime, pytz  @property def isnew(self):     return pytz.utc.localize(datetime.datetime.now())-self.user.date_joined < datetime.timedelta(days=40) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -