Skip to content

Commit

Permalink
fix: use read replica db for admin
Browse files Browse the repository at this point in the history
For NAUUserExtendedModel admin screen use the read replica database.
fixes fccn/nau-technical#66
  • Loading branch information
igobranco committed Mar 20, 2024
1 parent 720de38 commit 83c62e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nau_openedx_extensions/custom_registration_form/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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

0 comments on commit 83c62e5

Please sign in to comment.