Skip to content

Commit

Permalink
Improve mark/suspension admin-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikhorluck committed Sep 2, 2024
1 parent 160a932 commit 0830ce2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/marks/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.contrib import admin
from django.db.models import Count
from django.db.models.query import QuerySet
from django.http import HttpRequest
from django.utils import timezone
from django.utils.translation import gettext as _
from reversion.admin import VersionAdmin
Expand Down Expand Up @@ -39,13 +42,20 @@ class MarkAdmin(VersionAdmin):
"ruleset",
]

list_display = ["__str__", "category", "cause", "added_date", "weight"]
list_display = ["__str__", "affected_count", "cause", "added_date", "weight"]
readonly_fields = (
"expiration_date",
"ruleset",
)
search_fields = ("title",)

@admin.display(description="Antall påvirket")
def affected_count(self, mark: Mark):
return mark.affected_count

def get_queryset(self, request: HttpRequest) -> QuerySet[Mark]:
return super().get_queryset(request).annotate(affected_count=Count("users"))

def save_model(self, request, obj, form, change):
obj.last_changed_by = request.user
obj.save()
Expand All @@ -55,7 +65,8 @@ def save_model(self, request, obj, form, change):
class SuspensionAdmin(VersionAdmin):
model = Suspension
list_display = ["title", "user", "created_time", "expiration_date", "cause"]

fields = ["title", "user", "created_time", "expiration_date", "cause"]
readonly_fields = ["user", "created_time"]
exclude = ("payment_id",)


Expand Down

0 comments on commit 0830ce2

Please sign in to comment.