How to leave Choices field with no default value

Asked

Viewed 36 times

1

I currently have this class with a field Choice, tried to leave by default "deufault=None" can it remains bringing the field filled with Royal Flush, if I move to another existing City he accepts, I’m doing something wrong?

class Sessao(models.Model):
    MAO_DERROTA = (
        ('Royal Flush', 'Royal Flush'),
        ('Straight Flush', 'Straight Flush'),
        ('Quadra', 'Quadra'),
        ('Full House', 'Full House'),
        ('Flush', 'Flush'),
        ('Straight', 'Straight'),
        ('Trinca', 'Trinca'),
        ('Dois pares', 'Dois pares'),
        ('Um Par', 'Um Par'),
        ('Carta Alta', 'Carta Alta'),

    )
    data_ini_sessao = models.DateField(verbose_name='Data inicial da partida')
    torneio = models.ForeignKey(Torneio, verbose_name='Torneio', on_delete=models.CASCADE)
    buy_in = models.DecimalField(max_digits=10, decimal_places=2,verbose_name='Buy-in')
    jogadores = models.IntegerField(verbose_name='Qtd jogadores')
    premio = models.DecimalField(max_digits=10, decimal_places=2,verbose_name='Vlr Premio')
    saldo = models.DecimalField(max_digits=10, decimal_places=2,verbose_name='Saldo da partida')
    colocacao = models.IntegerField(verbose_name='Colocação')
    data_fin_sessao = models.DateField(verbose_name='Data final da partida')
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    tempo = models.IntegerField(verbose_name='Tempo')
    comentario_sessao = models.TextField(blank=True)
    mao_derrota = models.CharField(max_length=50, choices=MAO_DERROTA, default=None)

1 answer

1


Alter MAO_DERROTA for:

MAO_DERROTA = (
    ('','..........'),  
    ('Royal Flush', 'Royal Flush'),
    ('Straight Flush', 'Straight Flush'),
    ('Quadra', 'Quadra'),
    ('Full House', 'Full House'),
    ('Flush', 'Flush'),
    ('Straight', 'Straight'),
    ('Trinca', 'Trinca'),
    ('Dois pares', 'Dois pares'),
    ('Um Par', 'Um Par'),
    ('Carta Alta', 'Carta Alta'),
)

Change the dots (.......), for whatever you want.

  • Oh right, if it is a mandatory field it does not let save being in this first correct option?

  • 1

    test, gave right, up to the obligation of choice, thank you very much Sidon

  • Yes, but the ideal is to treat this and warn the user.

  • put it like this: MAO_DERROTA = ( (', 'Choose your hand'),

  • Good! Django is badass! :-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.