Skip to content

Commit

Permalink
admin: Show the sub periods involved in SubscriptionPayment admin list
Browse files Browse the repository at this point in the history
  • Loading branch information
dehnert committed Feb 20, 2025
1 parent 979d9f8 commit f92c704
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion squaresdb/gate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,21 @@ class Admin_SubscriptionPayment(VersionAdmin):
# In an ideal world, we'd show the periods in the list, but ManyToManyField
# isn't supported in list_display.
actions = [mail_merge]
list_display = ['time', 'person', 'at_dance', 'payment_type', ]
list_display = ['time', 'person', 'at_dance', 'payment_type', 'get_periods']
ordering = ['at_dance', 'person']
list_filter = ['periods', 'payment_type']
search_fields = ['person__name', 'person__email']
date_hierarchy = 'time'

def get_queryset(self, request):
# Based on https://stackoverflow.com/a/67639818/1797496
qs = super().get_queryset(request)
return qs.prefetch_related('periods')

@admin.display(description="Periods")
def get_periods(self, obj):
return ", ".join([period.name for period in obj.periods.all()])


@admin.register(gate_models.DancePayment)
class Admin_DancePayment(VersionAdmin):
Expand Down
22 changes: 22 additions & 0 deletions squaresdb/gate/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,25 @@ def test_render_books(self):
logger.info(response)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Payments")

class AdminTestCase(TestCase):
fixtures = ['people.json', 'sample.json']

def setUp(self):
self.user = get_user('view_attendee')
self.user.is_staff = True
content_type = ContentType.objects.get_for_model(gate_models.SubscriptionPayment)
permission = Permission.objects.get(content_type=content_type,
codename='view_subscriptionpayment')
self.user.user_permissions.add(permission)
self.user.save()

def test_admin_subscriptionpay(self):
client = Client()
client.force_login(self.user)
path = reverse('admin:gate_subscriptionpayment_changelist', )
with self.assertNumQueries(14):
response = client.get(path)
logger.info(response)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Select subscription payment to ")

0 comments on commit f92c704

Please # to comment.