Error: An admin for model "User" has to be registered to be referenced by TokenAdmin.autocomplete_fields. #9296
-
After updating to DRF 3.15.0 I am now getting the following error when starting my Django server:
I am using a custom AdminSite instance where only the ModelAdmins that I specifically register to it are shown in my admin site. I have not registered TokenAdmin to my AdminSite, because it's not something we want to see in our admin site. I also have a custom User model, but its ModelAdmin is registered with my custom AdminSite. It seems that DRF can't handle this situation. I guess that it only looks through the default AdminSite for what is registered there? How can I make DRF just ignore the TokenAdmin? I don't want it in our admin site, as we don't use tokens (only sessions). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You can unregister the models you don't want with: from django.contrib import admin
from rest_framework.authtoken.models import TokenProxy
admin.site.unregister(TokenProxy) https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.AdminSite.unregister You can probably do that anywhere, but it might have to be in an |
Beta Was this translation helpful? Give feedback.
-
That doesn't work: I am not using the default admin site, I am not using its auto discover function, so nothing should be registered to it. And yeah, thus this error. |
Beta Was this translation helpful? Give feedback.
When you got this error, did you call
unregister
on you custom admin site or on the default admin site? DRF registers on the default site, so even though you're not using it, perhaps it's making the Django checks fail?Do you have
'rest_framework.authtoken'
in yourINSTALLED_APPS
? If you're not using Tokens, I guess you shouldn't have it, but perhaps it's there?