diff --git a/vendor/registrasion/registrasion/models/people.py b/vendor/registrasion/registrasion/models/people.py index 561c3bb4..e36f2688 100644 --- a/vendor/registrasion/registrasion/models/people.py +++ b/vendor/registrasion/registrasion/models/people.py @@ -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.