I am trying to change the field order in the admin of a field in a django package (rest framework)
I define a new adminmanager, but get a 'Model Already Registered' Error. Surely there must be a way to do it?
from rest_framework.authtoken.models import Token
class AuthTokenAdmin(admin.ModelAdmin):
list_display = ('user', 'key',)
admin.site.register(Token, AuthTokenAdmin)
Administrative register is a Register used for administrative purposes in an administrative information system. An Administrative register should contain all objects to be administrated, the objects are identifiable, are updated, and the Variables in the Administrative register are used for administrative purposes.
The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.
The reason this error occurs is, the class Token
has already been registered with an admin class like this:
from django.contrib import admin
from rest_framework.authtoken.models import Token
class TokenAdmin(admin.ModelAdmin):
list_display = ('key', 'user', 'created')
fields = ('user',)
ordering = ('-created',)
admin.site.register(Token, TokenAdmin)
To change this, you first need to unregister
the old admin registration against the given class, and then register the new one.
Try this:
admin.site.unregister(Token) #First unregister the old class
admin.site.register(Token, AuthTokenAdmin) #Then register the new class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With