Asinox
Asinox

Reputation: 6865

Django, choices option field

i have a question about the choices option field.

i have this field:

SECUENCIA = (
             ('1','1'),
             ('2','2'),
             ('3','3'),
)
secuencia = models.IntegerField(max_length=1,choices=SECUENCIA)

All is fine in my forms for add or update but in my show view (template display) the field just appear like "(None)" and dont show the value (1 or 2 or 3).

Thanks :)

Upvotes: 9

Views: 7078

Answers (1)

ars
ars

Reputation: 123468

The first element of your choice tuple has to be the value that will be stored. In your case, it needs to be an integer:

SECUENCIA = (
             (1, '1'),
             (2, '2'),
             (3, '3'),
)

See the documentation for more information:

Upvotes: 17

Related Questions