0

The invoice_date field on one of my models is not showing up in my admin.

invoice_date = models.DateField(auto_now=True, auto_now_add=False, null=True, blank=True)

I've tried the following:

  • renaming the field
  • running makemigrations/migrations
  • restarting the server
  • deleting cookies

I can successfully write to the field and pull data from it, so it appears to be there and functioning as desired. I just can't see it in the admin.

I have no special code in my admin.py. I've just registered the model

admin.py

from userorders.models import UserCartItem
admin.site.register(UserCart)

Any suggestions are welcome! Thanks!

2 Answers 2

1

Accoring to Django's documentation:

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

You can circumvent this by explicitly defining it on the ModelAdmin class:

from userorders.models import UserCartItem

class UserCartItemAdmin(admin.ModelAdmin):
    list_display = ['invoice_date']
    fields = ['invoice_date']
    # if you want the field just to visible but not editable
    # readonly_fields = ['invoice_date']


admin.site.register(UserCartItem, UserCartItemAdmin)
0
0

You could try something following-

from userorders.models import UserCartItem

class UserCartItemAdmin(admin.ModelAdmin):
   list_display = ['field_name_1', 'field_name_2', 'invoice_date']

admin.site.register(UserCartItem, UserCartItemAdmin)
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.