doorcontrol: Add EventTicketType method to group by member/non-member
This commit is contained in:
parent
97502fe130
commit
58cc8cb2f8
@ -15,6 +15,7 @@ from django.db.models import (
|
||||
Q,
|
||||
Subquery,
|
||||
Sum,
|
||||
Value,
|
||||
When,
|
||||
)
|
||||
from django.db.models.functions import Coalesce
|
||||
@ -570,6 +571,28 @@ class EventMeetingTime(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class EventTicketTypeQuerySet(models.QuerySet["EventTicketType"]):
|
||||
def group_by_ticket_type(self):
|
||||
return self.values("is_members_ticket").annotate(
|
||||
label=Case(
|
||||
When(Q(is_members_ticket=True), Value("Members")),
|
||||
default=Value("Non-Members"),
|
||||
),
|
||||
actual_price=F("actual_price"),
|
||||
**{
|
||||
field: Sum(field)
|
||||
for field in [
|
||||
"quantity",
|
||||
"materials",
|
||||
"amount",
|
||||
"amount_without_materials",
|
||||
"instructor_revenue",
|
||||
"instructor_amount",
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class EventTicketTypeManager(models.Manager["EventTicketType"]):
|
||||
def get_queryset(self) -> models.QuerySet["EventTicketType"]:
|
||||
members_folder = Subquery(
|
||||
@ -627,7 +650,7 @@ class EventTicketTypeManager(models.Manager["EventTicketType"]):
|
||||
|
||||
|
||||
class EventTicketType(DBView):
|
||||
objects = EventTicketTypeManager()
|
||||
objects = EventTicketTypeManager.from_queryset(EventTicketTypeQuerySet)()
|
||||
|
||||
event = models.ForeignKey(
|
||||
EventExt, on_delete=models.CASCADE, related_name="ticket_types"
|
||||
|
Loading…
Reference in New Issue
Block a user