Пример #1
0
    def _create_games(self, n=1):
        if Color.objects.count() < Game.AVAILABLE_COLORS:
            print "Impossible to create games. No enough colors."
            print "ESCAPING..."
            return

        print "Populating Games"
        for i in range(n):
            available_colors = Color.objects.all().order_by('?')[:Game.AVAILABLE_COLORS]

            game = Game()
            game.initial_amount = random.randint(0, 100)
            game.percentage = random.randint(0, 100)
            game.payment = random.uniform(0, 5)
            game.start_date = timezone.now()
            game.end_date = game.start_date + datetime.timedelta(days=random.randint(3, 30))
            game.save()
            game.available_colors.add(*available_colors)
        print "SUCCESS"