This is a simple app that automatically registers all the models that have not yet been registered to the Django admin.
It also does the following:
- Adds all fields except
TextFieldtolist_display. - Optimizes the database queries by selecting related fields.
- Adds fields that have
choicesset tolist_filter. - If a model only has one
DateFieldorDateTimeFieldit adds that field to thedate_hierarchy - Sets
raw_id_fieldfor related fields andautocomplete_fieldsfor related fields that havesearch_fieldsset. - Only registers models that you haven't yet registered.
- Ignores models that you wish to exclude from the admin.
- Install django-admin-autoregister
pip install django-admin-autoregisteror
pipenv install django-admin-autoregister- Add
admin_autoregisterto the bottom INSTALLED_APPS setting like this:
INSTALLED_APPS = [
# ...
'admin_autoregister',
]Be extra careful to include it as the last app in the list, otherwise your own admin registrations will raise exceptions.
All your models should now be registered in the admin.
-
You can use the following settings to tweak the admin auto registration:
ADMIN_AUTOREGISTER_EXCLUDEis a list of models to exclude in the admin.- Defaults to
['contenttypes.ContentType', 'auth.Permission', 'session.Session', 'admin.LogEntry',]'
- Defaults to
ADMIN_AUTOREGISTER_EXCLUDE_INLINESis a boolean that determines whether or not to exclude models that are already registered as inlines of other models.- Defaults to
True
- Defaults to
ADMIN_AUTOREGISTER_UNREGISTER_LISTis a list of models to unregister from admin. This is usefull when you want to unregister models from other apps such as Celery, Oauth which are registered by default.- Defaults to
[]
- Defaults to
Each of the autoregister features can be used in your registered models by adding them as mixins.
The available mixins are:
admin_autoregister.mixins.ListDisplayAdminMixin- Populates thelist_displayautomatically.admin_autoregister.mixins.ListFilterAdminMixin- Populates thelist_filterattribute automatically.admin_autoregister.mixins.AutocompleteFieldsAdminMixin- Populates theraw_id_fieldsandautocomplete_fieldsattributes automatically.admin_autoregister.mixins.SelectRelatedFieldsAdminMixin- Automatically selects all related fields with the queryset.admin_autoregister.mixins.DateHierarchyAdminMixin- Automatically sets thedate_hierarchyif there's only oneDateTimeFieldorDateField
Contributions are very welcome - submit a PR!