Django Admin Not Displaying `creation_date` Field Despite Being in `list_display`

I have a Django project where I'm working on an e-commerce application. I'm using SQLite as my database, and I'm trying to add a creation_date field to my VendorProduct model so that it records when a product was created.

What I Did

I added the creation_date field to my VendorProduct model like this:

models.py (VendorProduct Model)

from django.db import models
from django.utils.timezone import now
from userauths.models import CustomUser

class VendorProduct(models.Model):
    user = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, null=True, blank=True)
    creation_date = models.DateTimeField(auto_now_add=True, blank=True, null=True)

    def __str__(self):
        return self.title

Migrations

I ran the following commands to apply the migration:

python manage.py makemigrations vendorpannel
python manage.py migrate vendorpannel

Then, I verified that the creation_date column exists in my database using:

from django.db import connection

with connection.cursor() as cursor:
    cursor.execute("PRAGMA table_info(vendorpannel_vendorproduct);")
    columns = cursor.fetchall()

for column in columns:
    print(column)

The output confirms that creation_date exists in my database:

(7, 'creation_date', 'datetime', 0, None, 0)

Admin Panel Configuration

I updated my admin panel to display creation_date:

admin.py

from django.contrib import admin
from .models import VendorProduct

class VendorProductAdmin(admin.ModelAdmin):
    list_display = ('creation_date')  
    readonly_fields = ('creation_date',) 

admin.site.register(VendorProduct, VendorProductAdmin)

Problem: creation_date Not Showing in Django Admin

Even after making these changes and applying migrations, the creation_date field is not appearing in the Django admin panel under list_display.

What I Tried

  1. Checked if the field exists in the database using SQL queries (confirmed ✅).
  2. Cleared Django cache and restarted the server:
    python manage.py collectstatic
    python manage.py runserver
    
  3. Checked if the field name is correct in list_display (confirmed ✅).
  4. Verified that list_display works for other fields (other fields display correctly, just creation_date is missing ❌).

Expected Outcome

  • I expect to see creation_date displayed in the Django admin panel under VendorProduct.
  • The field should be read-only and should not be manually editable.

Question

Why is creation_date not appearing in the Django admin panel, even though:

  • It exists in the database.
  • It's correctly added in list_display.
  • Migrations were applied successfully.

What am I missing here?

VendorProduct List view

list_display field is for List view only. It's the admin page listing instances of VendorProduct in your case.

On your screenshot you have Add view which shows only editable fields.

Since your creation_date field has auto_now_add option, it makes it non-editable.

If you want to manually provide creation_date, but still keep default now behavior then instead of auto_now_add use default option.

creation_date = models.DateTimeField(default=datetime.now, blank=True)

Then this field will show up in add form. Maybe try to remove it from read-only field if this is not enough

In all other cases this field should show up for existing instances

Вернуться на верх