samedi 27 juin 2015

Django - Time since model created

How du you calculate the time since a model was created? The model has the following field:

created_at = models.DateTimeField(auto_now_add=True)

This is what I tried:

from datetime import datetime, timedelta

@property
def time_since_created(self):
    return (datetime.now()-self.created_at).total_seconds()

But it did not work. Do anyone have any ideas?

Aucun commentaire:

Enregistrer un commentaire