From 95401cdbd0af416769d7cc06f14897698f45cdb7 Mon Sep 17 00:00:00 2001 From: Ivo Branco Date: Mon, 18 Mar 2024 22:06:48 +0000 Subject: [PATCH] fix: use read replica db for admin For NAUUserExtendedModel admin screen use the read replica database. fixes fccn/nau-technical#66 --- .../custom_registration_form/admin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nau_openedx_extensions/custom_registration_form/admin.py b/nau_openedx_extensions/custom_registration_form/admin.py index 2fb8fe5..ed5cb68 100644 --- a/nau_openedx_extensions/custom_registration_form/admin.py +++ b/nau_openedx_extensions/custom_registration_form/admin.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals +from common.djangoapps.util.query import use_read_replica_if_available # lint-amnesty, pylint: disable=import-error from django.contrib import admin from nau_openedx_extensions.custom_registration_form.models import NauUserExtendedModel @@ -19,9 +20,6 @@ class NauUserExtendedModelAdmin(admin.ModelAdmin, ExportCsvMixin): search_fields = ( "user__email", "user__username", - "cc_nif", - "cc_first_name", - "cc_last_name", ) readonly_fields = ( "openedx_username", @@ -60,3 +58,9 @@ def openedx_username(self, instance): return instance.user.username except Exception as error: return str(error) + + def get_search_results(self, request, queryset, search_term): + qs, use_distinct = super().get_search_results(request, queryset, search_term) + if not search_term or len(search_term) < 3: + qs = NauUserExtendedModel.objects.none() + return use_read_replica_if_available(qs), use_distinct