Comments (6)
I've got the same issue, reverted back to 3.14.0.
from django-rest-framework.
I am also now seeing this error after bumping from 3.14.0 to 3.15.0. From Google, it appears this is coming from Django's command validation, not DRF specifically, but I believe it was introduced to DRF via this pull request, and it's unclear how to resolve the issue in DRF. The error suggests registering an admin model for "User", but I already have been, and doing so before registering the TokenAdmin
:
I do extend the AdminSite:
class PlatformAdminSite(AdminSite):
"""
Creates a base AdminSite. Models and URLs should be attached to an instance of this class.
"""
site_header = settings.PROJECT_NAME + ' Administration'
site_title = site_header
index_title = settings.PROJECT_NAME
admin_site = PlatformAdminSite()
And register against that:
from django.contrib.auth import admin, get_user_model
from rest_framework.authtoken import admin as drf_admin
from rest_framework.authtoken.models import Token
class UserAdmin(admin.UserAdmin, BaseModelAdmin):
# ... My extended UserAdmin code
class TokenAdmin(drf_admin.TokenAdmin):
# ... My extended TokenAdmin code
# Then register the models to the admin
admin_site.register(get_user_model(), UserAdmin)
admin_site.register(Token, TokenAdmin)
It fails with this error. If I register directly against admin.site.register
instead of my extended AdminSite
, it works again. So what has changed with this release, and what do we need to change? Do we need to register something elsewhere, or has the way we need to extend AdminSite
changed?
from django-rest-framework.
I noticed that you have a custom User
model, right? So I think what happens is:
- Django register the default User model with the default admin
- DRF register the TokenProxy model with the default admin. But this model references your custom User model:
However, Django checks that the autocomplete_fields
matches a model which is registered in the admin, but the user model registered in the default admin is the default one, not the custom one.
The simplest thing might be to revert the PR that caused it (I was waiting for this specific fix, but it doesn't work in all cases) and perhaps expand the documentation, which already explains how to patch the TokenAdmin
. If folks want auto-complete fields, they can fix it in user land.
from django-rest-framework.
Agreed I think that PR should be reverted. DRF can either set TokenAdmin.autocomplete_fields
as it does here, or call admin.site.register(TokenProxy, TokenAdmin)
, as it does here.
It can't do both, making this decision is too implementation-specific and thus won't work in all cases.
from django-rest-framework.
Created a PR to revert. For those looking to apply the same logic and enable auto-complete once the revert PR is merged, here is the code:
from rest_framework.authtoken.admin import TokenAdmin
TokenAdmin.autocomplete_fields = ("user",)
from django-rest-framework.
temporary solution
added search_fields in my custom admin class
search_fields = ("USERNAME_FIELD",)
from django-rest-framework.
Related Issues (20)
- 3.15 not backwards compatible with 3.14 - "View' should either include a `queryset` attribute, or override the `get_queryset()` method." HOT 11
- 3.15 backward compatibility issue with 3.14 - `rest_framework.filters.SearchFilter.get_search_terms` returns `str` instead of `list` HOT 3
- New handling of default= for ModelSerializer HOT 6
- 3.15 regression: ListSerializer ValidationErrors silently changed return type
- 3.15 regression: ListSerializer ValidationError nested structure silently changed HOT 1
- 3.15 regression: UpdateModelMixin breaks views using Manager objects as queryset HOT 4
- Version 3.15.1 HOT 1
- 3.15 regression: Unset default namespace version suddenly raises 404 HOT 3
- 3.15(.1?) regression: optional fields in serializers are suddenly required (or need explicit None passed) HOT 11
- UniqueConstraint violation_error_message as error response in drf
- rest-framework Supports async class views ?
- 3.15 regression: Serializer validation failed for unique together constraint HOT 2
- Revert changes to `CursorPagination` that caused serious performance regression HOT 3
- Router.register cannot merge with urlpatters HOT 3
- UniqueTogetherValidator does not comply to Database standards
- HyperlinkedModelSerializer doesn't respect SECURE_PROXY_SSL_HEADER settings
- 3.15 is raising required error on model nullable fields HOT 6
- DRF generic views not fire post_save signal HOT 11
- [self-tests] cleanup order of `TestUrlPatternTestCase` HOT 1
- a question about BooleanField HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-framework.