如何在 django admin 中显示固定下拉菜单?
我想在下拉列表中显示优先级信息。目前我正在使用整数字段来存储优先级,但我想显示高/中/低而不是让用户输入优先级。
一种近似的方法是使用存储 3 个元素的优先级数据库,1:高、2:中、3:低,但这似乎有点矫枉过正。
任何更简单的方法将不胜感激!
贾森
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以指定字段的选择 http://www.djangoproject.com/documentation/models/choices /。
You can specify choices for a field http://www.djangoproject.com/documentation/models/choices/.
您可以这样编写模型:
您可以从 文档 中阅读更多内容
You could write your model like this:
You read more from the documentation
您应该能够向模型元素添加选择
,因此:
将在数据库中存储 H、M、L,但显示高、中、低。管理员将具有选项属性的默认字段设置为下拉选择器
You should be able to add choices to the model element
So:
Would store H,M,L in the DB, but present High, Medium, Low. Admin defaults fields with the choices attribute to a drop down selector