This is a combination of the answers by Hunger and using a decorator as suggested by Rahul Kumar:
In your admin.py, you just need:
@admin.register(Rating)
class RatingAdmin(admin.ModelAdmin):
readonly_fields = ('date',)
The fields specified in readonly_fields
will appear in the add and change page i.e. inside the individual record. And - of course - are not editable.
The fields in list_display
will constitute the representation in the main list page of the admin (i.e. the list of all records). In this case, it makes sense not to specify list_display = ('date',)
only, because you will see only the dates. Instead, include also the main title / name of the record.
Example:
readonly_fields = ('title', 'date',)
if in the models.py this model is defined as:
class Rating(models.Model):
title = models.CharField('Movie Title', max_length=150)
...
date = models.DateTimeField(editable=True, auto_now_add=True)
def __str__(self):
return self.title
auto_now_add
via the admin after the entry has first been created? – Gaspard