Improve searchability of contributor admin view
authorJonathan S. Katz <jonathan.katz@excoventures.com>
Mon, 30 Jan 2023 22:43:40 +0000 (17:43 -0500)
committerJonathan S. Katz <jonathan.katz@excoventures.com>
Mon, 30 Jan 2023 22:43:40 +0000 (17:43 -0500)
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
pgweb/contributors/migrations/0001_initial.py
pgweb/contributors/models.py

index 3d0675c870ed075e1420002922a808db0ea8e2c3..cdb733b95c2331bcb0b94dade67612eb7f0f2226 100644 (file)
@@ -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)
index 8f11bb2ff6d2d33ac34874d16b25361f52b0d8f5..ed7c84f2e31699dc53de15625346bfecba703e56 100644 (file)
@@ -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',
index 58f0ab9123973ecdd46cea1505fe0bf25246e5dd..4e6bf5c07fdd5f4d6cf652539b88d8bf29e67d6b 100644 (file)
@@ -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)