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,
|
Q,
|
||||||
Subquery,
|
Subquery,
|
||||||
Sum,
|
Sum,
|
||||||
|
Value,
|
||||||
When,
|
When,
|
||||||
)
|
)
|
||||||
from django.db.models.functions import Coalesce
|
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"]):
|
class EventTicketTypeManager(models.Manager["EventTicketType"]):
|
||||||
def get_queryset(self) -> models.QuerySet["EventTicketType"]:
|
def get_queryset(self) -> models.QuerySet["EventTicketType"]:
|
||||||
members_folder = Subquery(
|
members_folder = Subquery(
|
||||||
@ -627,7 +650,7 @@ class EventTicketTypeManager(models.Manager["EventTicketType"]):
|
|||||||
|
|
||||||
|
|
||||||
class EventTicketType(DBView):
|
class EventTicketType(DBView):
|
||||||
objects = EventTicketTypeManager()
|
objects = EventTicketTypeManager.from_queryset(EventTicketTypeQuerySet)()
|
||||||
|
|
||||||
event = models.ForeignKey(
|
event = models.ForeignKey(
|
||||||
EventExt, on_delete=models.CASCADE, related_name="ticket_types"
|
EventExt, on_delete=models.CASCADE, related_name="ticket_types"
|
||||||
|
Loading…
Reference in New Issue
Block a user