示例#1
0
    def _create_card(self, player):
        try:
            song_pks = Song.objects.values_list("pk", flat=True)

            selected_pks = (random.sample(list(song_pks)[:16], 5) +
                            random.sample(list(song_pks)[16:32], 5) +
                            random.sample(list(song_pks)[32:48], 5) +
                            random.sample(list(song_pks)[48:64], 5) +
                            random.sample(list(song_pks)[64:], 5))
            songs = Song.objects.filter(pk__in=selected_pks)

            new_card = Card()
            new_card.player = player
            new_card.items = songs
            new_card.full_clean()
            new_card.save()
            return False
        except:
            return True
def CreateStandardDeck(deck):
    suits = ["S", "H", "C", "D"]
    values = [
        "Ace",
        "Two",
        "Three",
        "Four",
        "Five",
        "Six",
        "Seven",
        "Eight",
        "Nine",
        "Ten",
        "Jack",
        "Queen",
        "King",
    ]

    for suit in suits:
        for value in values:
            new_card = Card(suit=suit, value=value, deck=deck)
            new_card.save()