Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use read replica db for admin #43

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading