简体   繁体   中英

Django-Rest-Framework field naming remap

I have python classes written in pythonic naming conventions (eg multiple_words_with_underscores ). When exposed through Django-Rest-Framework, I want to redo the naming convention to camelCase to be more javascript-esque. Is there a built in way to do this with the Django-Rest-Framework serializers or do I need to explicitly name the columns?

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.

You can use djangos field.verbose_name attribute like this:

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. You can have your frontend use this parameter where necessary to show the labels you wish

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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