1👍
✅
The traceback error is explaining the problem to you:
unsupported operand type(s) for -: ‘datetime.datetime’ and ‘datetime.date’
This says that you cannot subtract a datetime.datetime
from a datetime.date
. In your case, self.created_at
appears to be a date
but your use of datetime.now()
and timedelta()
suggest that you really want to be dealing with datetime
s.
Therefore, the solution is to either
- make sure that
created_at
is adatetime
, or - change
datetime.now()
todate.today()
and changetimedelta(hours=48)
totimedelta(days=2)
These will behave a little differently so pick one depending on whether things expire after two calendar days or in 48 hours.
Source:stackexchange.com