58👍
✅
If self.pk
is None
it is a new record.
def save(self):
if self.pk is None:
self.created = datetime.today()
self.modified = datetime.today()
super(ProjectCost, self).save()
This topic has been discussed also here
9👍
The preferred solution in modern Django is to check self._state.adding
Unfortunately this is not currently documented, but there is an open task to do so
https://code.djangoproject.com/ticket/31502
- [Django]-Using django-admin on windows powershell
- [Django]-Name '_' is not defined
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
Source:stackexchange.com