Add ticket_type property to Attendee

This vastly simplifies templates and many many things which need to
look this up.
This commit is contained in:
James Polley 2018-01-01 15:42:41 +11:00
parent eac35f3604
commit 0e1038de97

View file

@ -1,11 +1,13 @@
from registrasion import util
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from model_utils.managers import InheritanceManager
from registrasion.models.commerce import Invoice, ProductItem
# User models
@ -45,6 +47,19 @@ class Attendee(models.Model):
completed_registration = models.BooleanField(default=False)
guided_categories_complete = models.ManyToManyField("category", blank=True)
@property
def ticket_type(self):
tickets = ProductItem.objects.select_related(
"product","product__category","cart",
)
tickets = tickets.filter(
product__category=settings.TICKET_PRODUCT_CATEGORY,
cart__invoice__status=Invoice.STATUS_PAID,
cart__invoice__user=self.user
)
if len(tickets) >1:
raise ValueError("Too many tickets for attendee %s", self)
return tickets[0].product.name
class AttendeeProfileBase(models.Model):
''' Information for an attendee's badge and related preferences.