From 9b5509adf39a654a2fb714a565575d09dafa2b06 Mon Sep 17 00:00:00 2001 From: Haki Benita Date: Sat, 21 Jul 2018 16:14:43 +0300 Subject: [PATCH] authtoken/admin: Use raw_id_fields for user field When attempting to create an authtoken from the admin Django will generate a select box with all the users in the DB as options. In enviroments with a lot of users this will make the page unreponsive. Starting Django 2.0, there is a new pption that addresses this issue - raw_id_field[0]. This option will render the user selection as a special widget that does not require rendering a list of all the users in the DB. [0] https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields --- rest_framework/authtoken/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rest_framework/authtoken/admin.py b/rest_framework/authtoken/admin.py index 1a507249b..15fe41a4f 100644 --- a/rest_framework/authtoken/admin.py +++ b/rest_framework/authtoken/admin.py @@ -7,6 +7,7 @@ class TokenAdmin(admin.ModelAdmin): list_display = ('key', 'user', 'created') fields = ('user',) ordering = ('-created',) + raw_id_fields = ('user',) admin.site.register(Token, TokenAdmin)