Why does django-lint tell me the `auto_now_add` is deprecated?

后端 未结 2 866
花落未央
花落未央 2021-01-02 11:01

Hi fellow Djangonauts:

I checked my project with django-lint, and it yields:

W:211,16:MyModel: timestamp: Uses superceded auto_now or auto_now_add


        
相关标签:
2条回答
  • 2021-01-02 11:22

    auto_now and auto_now_add are considered harmful, because you have absolutely no way to change the value via django (say for example, in the admin interface).

    This is an inconsitency with other flags, and django people generally don't like that sort of magic.

    0 讨论(0)
  • 2021-01-02 11:34

    The correct fix is to pass a callable as the field's default that returns the appropriate datetime, e.g. datetime.datetime.now.

    0 讨论(0)
提交回复
热议问题