Skip to content

Commit

Permalink
New: Add source key filter to chants
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahankinson committed Aug 8, 2024
1 parent 3e8f70c commit 443f8ca
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions django/cantusdb_project/main_app/admin/chant.py
Original file line number Diff line number Diff line change
@@ -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):

Expand All @@ -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",
)
Expand Down

0 comments on commit 443f8ca

Please sign in to comment.