From 3af6ae009731d94f7f9a41094c4594a4f3c7bd67 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Sun, 4 Aug 2024 12:27:02 +0200 Subject: [PATCH] Add some more admin controls --- src/accounting/admin.py | 4 +++- src/accounting/models.py | 6 ++++++ src/membership/admin.py | 4 ++++ .../0008_alter_membership_membership_type.py | 19 +++++++++++++++++++ src/membership/models.py | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/membership/migrations/0008_alter_membership_membership_type.py diff --git a/src/accounting/admin.py b/src/accounting/admin.py index b8b311c..11d2219 100644 --- a/src/accounting/admin.py +++ b/src/accounting/admin.py @@ -43,7 +43,9 @@ class OrderAdmin(admin.ModelAdmin): inlines = (OrderProductInline,) form = OrderAdminForm - list_display = ("member", "description", "created", "is_paid") + list_display = ("member", "description", "created", "is_paid", "total_with_vat") + search_fields = ("member__email", "membership__membership_type__name", "description") + list_filter = ("is_paid", "membership__membership_type") @admin.register(models.Payment) diff --git a/src/accounting/models.py b/src/accounting/models.py index d7f7315..13abd88 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -4,6 +4,7 @@ from hashlib import md5 from typing import Self from django.conf import settings +from django.contrib import admin from django.db import models from django.db.models.aggregates import Sum from django.utils.translation import gettext as _ @@ -96,6 +97,11 @@ class Order(CreatedModifiedAbstract): return sum(item.vat * item.quantity for item in self.items.all()) @property + @admin.display( + ordering=None, + description="Total (incl. VAT)", + boolean=False, + ) def total_with_vat(self) -> Money: """Return the TOTAL amount WITH VAT.""" return self.total + self.total_vat diff --git a/src/membership/admin.py b/src/membership/admin.py index a08de86..6ccb55e 100644 --- a/src/membership/admin.py +++ b/src/membership/admin.py @@ -29,6 +29,10 @@ admin.site.unregister(User) class MembershipAdmin(admin.ModelAdmin): """Admin for Membership model.""" + list_display = ("user", "period", "membership_type", "activated", "revoked") + list_filter = ("period", "membership_type", "activated", "revoked") + search_fields = ("membership_type__name", "user__email", "user__first_name", "user__last_name") + @admin.register(MembershipType) class MembershipTypeAdmin(admin.ModelAdmin): diff --git a/src/membership/migrations/0008_alter_membership_membership_type.py b/src/membership/migrations/0008_alter_membership_membership_type.py new file mode 100644 index 0000000..1814aae --- /dev/null +++ b/src/membership/migrations/0008_alter_membership_membership_type.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1b1 on 2024-08-04 10:26 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('membership', '0007_membership_activated_membership_activated_on_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='membership', + name='membership_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='memberships', to='membership.membershiptype', verbose_name='membership type'), + ), + ] diff --git a/src/membership/models.py b/src/membership/models.py index f00c458..9483d0f 100644 --- a/src/membership/models.py +++ b/src/membership/models.py @@ -125,7 +125,7 @@ class Membership(CreatedModifiedAbstract): membership_type = models.ForeignKey( "membership.MembershipType", related_name="memberships", - verbose_name=_("subscription type"), + verbose_name=_("membership type"), on_delete=models.PROTECT, )