A subclass of Django's ModelAdmin
for use with models that are only meant to
have one record. This is useful for things like site-wide settings.
Register a model with SingleModelAdmin
:
from django.contrib import admin
from singlemodeladmin import SingleModelAdmin
from my_app.models import MyModel
admin.site.register(MyModel, SingleModelAdmin)
You can also subclass SingleModelAdmin
instead of Django's ModelAdmin
, and
it will work as expected:
from django.contrib import admin
from singlemodeladmin import SingleModelAdmin
from my_app.models import MyModel
class MyModelAdmin(SingleModelAdmin):
list_display = ['my_field']
admin.site.register(MyModel, MyModelAdmin)
pip install singlemodeladmin
- If there is only one object, the changelist will redirect to that object.
- If there are no objects, the changelist will redirect to the add form.
- If there are multiple objects, the changelist is displayed with a warning
- Attempting to add a new record when there is already one will result in a warning and a redirect away from the add form.
- 1.4
- 1.5
- 1.6
- 1.7
- 1.8
- 1.9
- 1.10
- 1.11
- 2.0
- 2.1
- 2.6
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7