views:

42

answers:

2

Hi folks,

I have a model such as the following:

class Item(models.Model):

    name = models.CharField(max_length=150)
    created = models.DateTimeField(auto_now_add=True)

the admin class is the following:

class ItemAdmin(admin.ModelAdmin):

    list_display = ('name', 'created')

the created field does not seem to exist

Is there some basic Django knowledge that I am missing or have forgotten?

+1  A: 

Strange. I tried out your example and it worked perfectly well (Django 1.2.1, Python 2.6.2) Can you verify that:

  1. The field exists in the database (fire a SQL query perhaps)
  2. Check your admin.py (again) for any differences.

Update

@Daniel's answer is more likely to help the OP.

Manoj Govindan
+4  A: 

When you say the field does not exist, do you mean that it is not showing on the admin change form? This is expected behaviour when using auto_now_add. If you want the field to get a default value on creation but still be editable, use default=datetime.datetime.now instead.

Daniel Roseman
+1. Ah. Good interpretation of the question. The field will indeed not show up in the admin add/edit page. It will however show up in the list page.
Manoj Govindan