Posted By

munkypot on 10/01/10


Tagged

database time date model DateTime timestamp created django inherit abstract updated autonow


Versions (?)

Timestamp Inherit Model (Versione 2)


 / Published in: Django
 

Simula in Django i campi created e updated aggiornati automaticamente alla creazione e alla modifica del record (Versione 2 senza funzione save ridefinita)

  1. from django.db import models
  2.  
  3. # Create your models here.
  4. class Timestamp(models.Model):
  5. created = models.DateTimeField(auto_now_add=True, editable=False)
  6. updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False)
  7.  
  8. class Meta:
  9. abstract = True
  10.  
  11. class Example(Timestamp):
  12. name = models.CharField(max_length=255)

Report this snippet  

You need to login to post a comment.