Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display fixed dropdown in django admin?

I would like to display priority information in a drop down. Currently i am using a integer field to store the priority, but i would like to display high/medium/low instead of letting user type in a priority.

A way to approximate this is to use a Priority database which stores 3 elements, 1:high, 2:medium, 3:low, but it seems like an overkill.

Any easier way would be much appreciated!

Jason

like image 394
FurtiveFelon Avatar asked Dec 03 '22 12:12

FurtiveFelon


1 Answers

You can specify choices for a field http://www.djangoproject.com/documentation/models/choices/.

PRIORITY_CHOICES = ((1, 'High'),
                    (2, 'Medium'),
                    (3, 'Low'))

class MyModel(models.Model):
    priority = models.IntegerField(choices=PRIORITY_CHOICES)
like image 111
Bernhard Vallant Avatar answered Dec 25 '22 04:12

Bernhard Vallant