4

I have a model (as below) and in that, I've set auto_now_add=True for the DateTimeField

class Foo(models.Model):
    timestamp = models.DateTimeField(auto_now_add=True)

From the doc,

As currently implemented, setting auto_now or auto_now_add to True will cause the field to have editable=False and blank=True set.

Q: How Can I show this auto_now_add field in Django Admin? (by default Django Admin doesn't show auto_now_add fields)

JPG
  • 82,442
  • 19
  • 127
  • 206

1 Answers1

9

We can forcefully show the auto_now_add=True fields by adding the particular field(s) to the readonly_fields - (Django doc) list

class FooAdmin(admin.ModelAdmin):
    readonly_fields = ('timestamp',)


admin.site.register(Foo, FooAdmin)
JPG
  • 82,442
  • 19
  • 127
  • 206