88👍
Sure. Just access the choices
attribute of a Model field:
MyModel._meta.get_field('foo').choices
my_instance._meta.get_field('foo').choices
14👍
If you’re declaring your choices like this:
class Topic(models.Model):
PRIMARY = 1
PRIMARY_SECONDARY = 2
TOPIC_LEVEL = ((PRIMARY, 'Primary'),
(PRIMARY_SECONDARY, 'Primary & Secondary'),)
topic_level = models.IntegerField('Topic Level', choices=TOPIC_LEVEL,
default=1)
Which is a good way of doing it really. See: http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/
Then you can get back the choices simply with Topic.TOPIC_LEVEL
- [Django]-In Django Admin how do I disable the Delete link
- [Django]-Django ORM – objects.filter() vs. objects.all().filter() – which one is preferred?
- [Django]-Django development IDE
- [Django]-IntegrityError duplicate key value violates unique constraint – django/postgres
- [Django]-Python Socket.IO client for sending broadcast messages to TornadIO2 server
- [Django]-Django Queryset with year(date) = '2010'
Source:stackexchange.com