开发者

Datetime field on Django to store the date of insertion of row?

开发者 https://www.devze.com 2023-02-19 18:21 出处:网络
I\'m new to Django. I\'m starting a new App and I\'m currently on the Models. I need to store the date of the insertion of the line and when the line suffer from an UPDATE I need to store that date t

I'm new to Django. I'm starting a new App and I'm currently on the Models.

I need to store the date of the insertion of the line and when the line suffer from an UPDATE I need to store that date too.

My models.py

from django.db import models

class Directorio(models.Model):
    n_site           = models.CharField(max_length=60)
    url              = models.CharField(max_length=200)
    user_db_ins      = models.CharField(max_lenght=50)
    user_db_upd      = models.CharField(max_lenght=50)
    user_system_ins  = models.Char开发者_运维技巧Field(max_lenght=50)
    user_system_upd  = models.CharField(max_lenght=50)
    date_inserted    = 
    date_last_update =

How can I define the "date_inserted" and the "date_last_update"? I usually use a trigger to do this.

Can someone give me a clue on how to do it in the Django way?

Best Regards,


Documented in django here.

date_inserted    = models.DateTimeField(auto_now_add=True)
date_last_update = models.DateTimeField(auto_now=True)
0

精彩评论

暂无评论...
验证码 换一张
取 消