Django

Code

Ticket #555: django-core-meta-init.py.diff

File django-core-meta-init.py.diff, 0.8 kB (added by eric@ericwalstad.com, 2 years ago)

Patch to update date/time fields with whatever was saved into the database.

  • django/core/meta/__init__.py

    old new  
    10271027        if opts.has_auto_field and not pk_set: 
    10281028            setattr(self, opts.pk.attname, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 
    10291029    db.db.commit() 
     1030 
     1031    # Update the auto_now and auto_now_add fields to the values just inserted 
     1032    # into the database 
     1033    i = 0 
     1034    for f in non_pks: 
     1035        if isinstance(f, DateField): 
     1036            if f.auto_now or (f.auto_now_add and not record_exists): 
     1037                setattr(self, f.attname, db_values[i]) 
     1038        i += 1 
     1039 
    10301040    # Run any post-save hooks. 
    10311041    if hasattr(self, '_post_save'): 
    10321042        self._post_save()