import factory
from django.contrib.auth.models import User
from django.utils import timezone
from factory import LazyAttribute, post_generation
from factory.django import DjangoModelFactory


class CreateStaffUser(DjangoModelFactory):
    email = "ture@example.com"
    is_staff = True

    class Meta:
        model = User

    @factory.post_generation
    def password(self, create, extracted, **kwargs):
        self.set_password(extracted)
        self.save()


class CreateVenue(DjangoModelFactory):
    class Meta:
        model = 'venue.Venue'

    @post_generation
    def num_seats(self, create, num_seats, **kwargs):
        if not num_seats:
            return
        group = CreateSeatingGroup(venue=self)
        CreatePricingModel(seating_group=group, prices={"student": 200, "normal": 250})
        for i in range(num_seats):
            CreateSeat(group=group)


class CreateSeatingGroup(DjangoModelFactory):
    class Meta:
        model = 'venue.seatinggroup'


class CreateSeat(DjangoModelFactory):
    x_pos = 0
    y_pos = 0

    class Meta:
        model = 'venue.seat'


class CreateShow(DjangoModelFactory):
    date = timezone.now()
    production = factory.SubFactory('factories.factories.CreateProduction')
    venue = factory.SubFactory('factories.factories.CreateVenue')

    class Meta:
        model = 'show.show'


class CreateProduction(DjangoModelFactory):
    class Meta:
        model = 'show.production'


class CreateReservation(DjangoModelFactory):
    class Meta:
        model = 'ticket.Reservation'
    session_timeout = timezone.now()


class CreateAccount(DjangoModelFactory):
    name = "Bonnie"
    email = "bonnie@example.com"

    class Meta:
        model = 'ticket.account'


class CreateTicket(DjangoModelFactory):
    price = 200
    account = factory.SubFactory('factories.factories.CreateAccount')

    class Meta:
        model = 'ticket.ticket'


class CreateVoucher(DjangoModelFactory):
    class Meta:
        model = 'ticket.voucher'

    amount = 100
    created_by = factory.SubFactory(CreateStaffUser)


class CreatePricingModel(DjangoModelFactory):
    class Meta:
        model = "ticket.PricingModel"

    valid_from = LazyAttribute(lambda a: timezone.now())

@@ -526,25 +526,25 @@
     model = 
-'
+%22
 venue.Venue'
@@ -542,17 +542,17 @@
 ue.Venue
-'
+%22
 %0A%0A    @p
@@ -943,33 +943,33 @@
         model = 
-'
+%22
 venue.seatinggro
@@ -970,17 +970,17 @@
 inggroup
-'
+%22
 %0A%0A%0Aclass
@@ -1077,20 +1077,20 @@
 l = 
-'
+%22
 venue.
-seat'
+Seat%22
 %0A%0A%0Ac
@@ -1180,33 +1180,33 @@
 tory.SubFactory(
-'
+%22
 factories.factor
@@ -1225,17 +1225,17 @@
 oduction
-'
+%22
 )%0A    ve
@@ -1251,33 +1251,33 @@
 tory.SubFactory(
-'
+%22
 factories.factor
@@ -1291,17 +1291,17 @@
 ateVenue
-'
+%22
 )%0A%0A    c
@@ -1331,19 +1331,19 @@
 l = 
-'
+%22
 show.
-show'
+Show%22
 %0A%0A%0Ac
@@ -1421,15 +1421,15 @@
 l = 
-'
+%22
 show.
-p
+P
 rodu
@@ -1433,17 +1433,17 @@
 oduction
-'
+%22
 %0A%0A%0Aclass
@@ -1510,25 +1510,25 @@
     model = 
-'
+%22
 ticket.Reser
@@ -1533,17 +1533,82 @@
 ervation
-'
+%22%0A%0A    show = factory.SubFactory(%22factories.factories.CreateShow%22)
 %0A    ses
@@ -1770,24 +1770,24 @@
 l = 
-'
+%22
 ticket.
-a
+A
 ccount
-'
+%22
 %0A%0A%0Ac
@@ -1874,17 +1874,17 @@
 Factory(
-'
+%22
 factorie
@@ -1908,17 +1908,17 @@
 eAccount
-'
+%22
 )%0A%0A    c
@@ -1948,23 +1948,23 @@
 l = 
-'
+%22
 ticket.
-t
+T
 icket
-'
+%22
 %0A%0A%0Ac
@@ -2039,24 +2039,24 @@
 l = 
-'
+%22
 ticket.
-v
+V
 oucher
-'
+%22
 %0A%0A  
@@ -2121,24 +2121,184 @@
 taffUser)%0A%0A%0A
+class CreateDiscount(DjangoModelFactory):%0A    class Meta:%0A        model = %22ticket.Discount%22%0A%0A    amount = 100%0A    voucher = factory.SubFactory(CreateVoucher)%0A%0A%0A
 class Create

Add better factories