69๐
โ
You probably want import datetime
, not from datetime import datetime
.
date
is a class on the datetime module, but it is also a method on the datetime.datetime
class.
๐คAdam Vandenberg
37๐
The top answer is correct, but if you donโt want to import all of datetime you can write
from datetime import date
and then replace
datetime.date.today()
with
date.today()
๐คJoe
- [Django]-DRF: custom ordering on related serializers
- [Django]-Django rest framework lookup_field through OneToOneField
- [Django]-How to reload modules in django shell?
5๐
You need do like this one (ipython output)
In [9]: datetime.today().date() Out[9]: datetime.date(2011, 2, 5)
So need to be
def was_published_today(self): return self.pub_date.date() == datetime.today().date()
๐คrootart
- [Django]-How to delete old image when update ImageField?
- [Django]-How to get the current url namespace using Django?
- [Django]-Django template can't see CSS files
Source:stackexchange.com