MacPython
MacPython

Reputation: 18271

Tuple Choices Django

If I have a GENDER_CHOICE Tuple in a model like so:

GENDER_CHOICES = (
    ('M', 'Male'),
    ('F', 'Female'),
)

Could I use Integers a swell:

GENDER_CHOICES = (
    ('1', 'Male'),
    ('2', 'Female'),
)

And have a IntegerField(max_length=1) to write to ?

Thanks.

Upvotes: 1

Views: 535

Answers (2)

Ben James
Ben James

Reputation: 125167

Absolutely, but '1' and '2' are not integers (although they might still work through some magic).

This would definitely work for an IntegerField:

GENDER_CHOICES = (
    (1, 'Male'),
    (2, 'Female'),
)

I don't believe an IntegerField has a max_length attribute. A PositiveSmallIntegerField would be appropriate if you want a small number of choices.

Upvotes: 1

Manoj Govindan
Manoj Govindan

Reputation: 74705

I think a PositiveSmallIntegerField would be a better fit.

Upvotes: 0

Related Questions