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:
		
							parent
							
								
									eac35f3604
								
							
						
					
					
						commit
						0e1038de97
					
				
					 1 changed files with 15 additions and 0 deletions
				
			
		|  | @ -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. | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 James Polley
						James Polley