DateTimeField doesn't show in admin system

后端 未结 7 1703
野的像风
野的像风 2020-12-05 01:27

How come my \"date\" field doesn\'t come up in the admin system?

In my admin.py file i have

from django.contrib import admin
from glasses.players.mod         


        
7条回答
  •  囚心锁ツ
    2020-12-05 02:19

    Depending on your specific needs, and any nuances in difference in behavior, you could do the following:

    from django.utils.timezone import now
    
    class MyModel(models.Model):
        date = models.DateTimeField(default=now)
    

    The default field can be used this way: https://docs.djangoproject.com/en/dev/ref/models/fields/#default

    The default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
    

    This does not set editable to False

提交回复
热议问题