简体   繁体   English

Django-Rest-Framework字段命名重映射

[英]Django-Rest-Framework field naming remap

I have python classes written in pythonic naming conventions (eg multiple_words_with_underscores ). 我已经写在Python的命名约定(如Python类multiple_words_with_underscores )。 When exposed through Django-Rest-Framework, I want to redo the naming convention to camelCase to be more javascript-esque. 当通过Django-Rest-Framework公开时,我想将命名约定重做为camelCase ,使其更具javascript风格。 Is there a built in way to do this with the Django-Rest-Framework serializers or do I need to explicitly name the columns? 是否有使用Django-Rest-Framework序列化程序执行此操作的内置方法,还是需要显式命名列?

I know how I can achieve this with list comprehension and the model._meta.fields attribute, I just want to know if there is a specific built-in way to accomplish this. 我知道如何使用列表理解和model._meta.fields属性来实现此目的,我只想知道是否有特定的内置方法来实现此目的。

You can use djangos field.verbose_name attribute like this: 您可以像这样使用djangos field.verbose_name属性:

name = models.CharField(max_length=100, verbose_name='New name')

This is automatically used in the POST/PUT forms but not in the object representation. 它会自动在POST / PUT表单中使用,但不会在对象表示中使用。 You can have your frontend use this parameter where necessary to show the labels you wish 您可以让前端在必要时使用此参数来显示所需的标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM