通过 Django 管理站点添加数据时更改大小写(大写/小写)
我正在配置我的新项目的管理站点,我有点怀疑我应该怎么做,在通过管理站点添加数据时点击“保存”,所有内容都转换为大写......
编辑:好的我知道 .upper 属性,并且我做了一个视图,我知道该怎么做,但我想知道管理站点上是否有任何可用于字段配置的属性:P
I'm configuring the admin site of my new project, and I have a little doubt on how should I do for, on hitting 'Save' when adding data through the admin site, everything is converted to upper case...
Edit: Ok I know the .upper property, and I I did a view, I would know how to do it, but I'm wondering if there is any property available for the field configuration on the admin site :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你必须覆盖 save()。 文档中的示例:
you have to override save(). An example from the documentation:
如果您的目标是在管理部分中保存时仅将内容转换为大写,那么您需要 创建一个带有自定义验证的表单以更改大小写:
如果您的目标是始终将值设为大写,那么您应该 < a href="http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods" rel="noreferrer">覆盖模型字段中的保存:
If your goal is to only have things converted to upper case when saving in the admin section, you'll want to create a form with custom validation to make the case change:
If your goal is to always have the value in uppercase, then you should override save in the model field:
文档中的更新示例建议使用 args、kwargs 来传递:
Updated example from documentation suggests using args, kwargs to pass through as: