1👍
✅
Today needs to be a DateField. I assume you’re trying to add only date not datetime, given your strftime formatting. Also, date should not be a CharField but rather a DateField or DateTimeField.
Furthermore, you need to use add_now or auto_add_now, depending on whether you want the value to be updated everytime the model is saved or only on creation, docs here
I imagine that the following is what you’re trying to do:
class Post(models.Model):
today = models.DateField(add_now=True)
date = models.DateField(auto_add_now=True)
title = models.CharField(max_length=100)
content = models.TextField(blank=True)
- [Answered ]-Django unexpected IntegrityError with PostgreSQL
- [Answered ]-Django PostgreSQL IntegerRangeField and update_or_create
Source:stackexchange.com