From 443f8ca0e6d1ac7068e03e78fd48ddfec7cd865d Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 8 Aug 2024 06:53:26 +0200 Subject: [PATCH] New: Add source key filter to chants This small change adds a text input filter to the chants for the source primary key. This allows chants to be filtered by source in the list. --- django/cantusdb_project/main_app/admin/chant.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/django/cantusdb_project/main_app/admin/chant.py b/django/cantusdb_project/main_app/admin/chant.py index 425ca9e12..0f89e22f5 100644 --- a/django/cantusdb_project/main_app/admin/chant.py +++ b/django/cantusdb_project/main_app/admin/chant.py @@ -1,10 +1,20 @@ from django.contrib import admin from main_app.admin.base_admin import EXCLUDE, READ_ONLY, BaseModelAdmin +from main_app.admin.filters import InputFilter from main_app.forms import AdminChantForm from main_app.models import Chant +class SourceKeyFilter(InputFilter): + parameter_name = "source_id" + title = "Source ID" + + def queryset(self, request, queryset): + if self.value(): + return queryset.filter(source_id=self.value()) + + @admin.register(Chant) class ChantAdmin(BaseModelAdmin): @@ -30,11 +40,13 @@ def get_source_siglum(self, obj): "incipit", "cantus_id", "id", + "source__holding_institution__siglum" ) readonly_fields = READ_ONLY + ("incipit",) list_filter = ( + SourceKeyFilter, "genre", "office", )