访问Django的field.choices [英] Access Django's field.choices
本文介绍了访问Django的field.choices的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法(不使用表单)访问模型字段的选择值?
Is there a way (without using a form) to access a model fields 'choices' value?
我想做一些像field.choices这样的东西,并且得到视图或模板中的值列表
I want to do something like field.choices - and get the list of values either in a view or template
推荐答案
当然,只需访问选项$一个模型字段的c $ c>属性。
MyModel._meta.get_field('foo').choices
my_instance._meta.get_field('foo').choices
这篇关于访问Django的field.choices的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文