From 11eadd7ae997cf1cdd26cf800fd048c0a29951fb Mon Sep 17 00:00:00 2001 From: "Jonathan S. Katz" Date: Mon, 30 Jan 2023 17:43:40 -0500 Subject: [PATCH] Improve searchability of contributor admin view This adds search fields (name, handle), a filter for contributor type, and default ordering options to make it easier to navigate this list in the admin panel. --- pgweb/contributors/admin.py | 4 ++++ pgweb/contributors/migrations/0001_initial.py | 2 +- pgweb/contributors/models.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pgweb/contributors/admin.py b/pgweb/contributors/admin.py index 3d0675c8..cdb733b9 100644 --- a/pgweb/contributors/admin.py +++ b/pgweb/contributors/admin.py @@ -16,6 +16,10 @@ class ContributorAdminForm(forms.ModelForm): class ContributorAdmin(admin.ModelAdmin): form = ContributorAdminForm autocomplete_fields = ['user', ] + list_display = ('__str__', 'user', 'ctype',) + list_filter = ('ctype',) + ordering = ('firstname', 'lastname',) + search_fields = ('firstname', 'lastname', 'user__username',) admin.site.register(ContributorType) diff --git a/pgweb/contributors/migrations/0001_initial.py b/pgweb/contributors/migrations/0001_initial.py index 8f11bb2f..ed7c84f2 100644 --- a/pgweb/contributors/migrations/0001_initial.py +++ b/pgweb/contributors/migrations/0001_initial.py @@ -44,7 +44,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='contributor', name='ctype', - field=models.ForeignKey(to='contributors.ContributorType', on_delete=models.CASCADE), + field=models.ForeignKey(to='contributors.ContributorType', on_delete=models.CASCADE, verbose_name='Contributor Type'), ), migrations.AddField( model_name='contributor', diff --git a/pgweb/contributors/models.py b/pgweb/contributors/models.py index 58f0ab91..4e6bf5c0 100644 --- a/pgweb/contributors/models.py +++ b/pgweb/contributors/models.py @@ -19,7 +19,7 @@ class ContributorType(models.Model): class Contributor(models.Model): - ctype = models.ForeignKey(ContributorType, on_delete=models.CASCADE) + ctype = models.ForeignKey(ContributorType, on_delete=models.CASCADE, verbose_name='Contributor Type') lastname = models.CharField(max_length=100, null=False, blank=False) firstname = models.CharField(max_length=100, null=False, blank=False) email = models.EmailField(null=False, blank=True) -- 2.39.5