I've ran into a typical problem where I have a ListField in a model.
I'd like to use the Django admin to play around with the object and the ListField isn't that crucial, it's a list of embedded objects that I can live without.
When I use this, I get the error on the main admin page. If I don't use the ModelAdmin object when registering the original Item object, I only get the error if I try to add an Item.
from django.contrib import admin
class ItemAdmin(admin.ModelAdmin):
exclude = ('bids',)
admin.site.register(Item, ItemAdmin)
How to properly exclude the "bids" ListField then?
Subclass
ListFieldand overrideformfieldso that it returnsNone.Returning
Nonefromformfield(...)means that the field should be excluded from all forms, so you need remove theexclude = ['bids']thing from yourModelAdmin.Alternatively, you can make
formfield(...)return a properforms.Fieldsubclass -- to display e.g. a text version, use something likeTo exclude it from the admin, you can still use
exclude.https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#django.db.models.Field.formfield
Put your field subclass into
yourapp/fields.py.