-3👍
✅
Try
import datetime
created = models.DateTimeField(default=datetime.datetime.now)
And about why this happening you can read over here: Django auto_now and auto_now_add and Django model field default
3👍
You can use pre_save signal to process loaddata(fixtures)
@receiver(pre_save, sender=MyModel)
def pre_save_for_conference_code_fixture(sender, instance, **kwargs):
if kwargs['raw']:
instance.updated_at = timezone.now()
if not instance.id:
instance.created_at = timezone.now()
https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-loaddata
- Django error: [<class 'decimal.InvalidOperation'>]
- Does anyone know about workflow frameworks/libraries in Python?
- Why isn't admin.autodiscover() called automatically in Django when using the admin, why was it designed to be called explicitly?
- Django app defaults?
Source:stackexchange.com