Exemplo n.º 1
0
class TileBet(models.Model):
    user = models.ForeignKey(User)
    cell = models.ForeignKey(TileCell)
    no_of_tickets = models.PositiveIntegerField()

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.cell.total_bets += self.no_of_tickets
            self.cell.save()
            cost_of_tickets = self.no_of_tickets * self.cell.game.ticket_cost
            profile = self.user.profile
            profile.points -= cost_of_tickets
            profile.save()
        return super(TileBet, self).save(*args, **kwargs)
Exemplo n.º 2
0
class CardCell(models.Model):
    SUITS = (("C", "Clubs"), ("S", "Spades"), ("D", "Diamonds"), ("H",
                                                                  "Hearts"))
    VALUES = (("J", "Jack"), ("Q", "Queen"), ("K", "King"))
    GROUPS = (("A", "A"), ("B", "B"), ("C", "C"))
    game = models.ForeignKey(Cards, related_name="cells")
    suit = models.CharField(max_length=1, choices=SUITS)
    value = models.CharField(max_length=1, choices=VALUES)
    group = models.CharField(max_length=1, choices=GROUPS)
    total_bets = models.PositiveIntegerField(default=0)
    winner = models.BooleanField(default=False)

    class Meta:
        unique_together = ("game", "suit", "value", "group")
Exemplo n.º 3
0
class CardBet(models.Model):
    user = models.ForeignKey(User)
    cell = models.ForeignKey(CardCell)
    no_of_tickets = models.PositiveIntegerField()

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.cell.total_bets += self.no_of_tickets
            self.cell.save()
            cost_of_tickets = self.no_of_tickets * self.cell.game.ticket_cost
            profile = self.user.profile
            profile.points -= cost_of_tickets
            profile.save()
            Transaction.objects.create(user=self.user,
                                       amount=-1 * cost_of_tickets)
        return super(CardBet, self).save(*args, **kwargs)
Exemplo n.º 4
0
class TileCell(models.Model):
    SUITS = (
        ("A", "A"),
        ("B", "B"),
    )
    VALUES = (
        ("1", "1"),
        ("2", "2"),
        ("3", "3"),
        ("4", "4"),
        ("5", "5"),
    )
    GROUPS = (("A", "A"), ("B", "B"), ("C", "C"))
    game = models.ForeignKey(Tiles, related_name="cells")
    suit = models.CharField(max_length=1, choices=SUITS)
    value = models.CharField(max_length=1, choices=VALUES)
    group = models.CharField(max_length=1, choices=GROUPS)
    total_bets = models.PositiveIntegerField(default=0)
    winner = models.BooleanField(default=False)

    class Meta:
        unique_together = ("game", "suit", "value", "group")
Exemplo n.º 5
0
class Cards(models.Model):
    ticket_cost = models.PositiveIntegerField(default=11)
    winner_prize = models.PositiveIntegerField(default=100)
    is_result_generated = models.BooleanField(default=False)
    created = models.DateTimeField(auto_now_add=True)