How to change the name of a field in model field?

18 views
Skip to first unread message

voger

unread,
Sep 2, 2016, 6:11:00 AM9/2/16
to django-res...@googlegroups.com
This is not a real problem and really not a big deal. Just my curiosity.

I was reading about best practices in building an API and I came across
to this
http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#snake-vs-camel

Lets say I have a model

class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='userprofile',
primary_key=True)
birth_date = birth_date = models.DateField(verbose_name='Birth Date',
default=timezone.now)

and a serializer

class UserListSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile

Is there any simple way to change birth_date field to camelCase without
having to use SerializerMethodField? Somehow defining a tuple or a map
maybe? I checked the documentation but I can't find something relevant.

Again not a big deal. Just curious.

Tom Christie

unread,
Sep 2, 2016, 6:46:07 AM9/2/16
to Django REST framework
This third party package is probably the best option: https://github.com/vbabiy/djangorestframework-camel-case

Tom Christie

unread,
Sep 2, 2016, 6:52:03 AM9/2/16
to Django REST framework
Tho as an aside, I'd prefer `snake_case` to `camelCase` as a general rule for API responses.

Javier Lázaro

unread,
Oct 5, 2016, 11:46:09 AM10/5/16
to Django REST framework, vogernew...@yahoo.gr
Hi.

snake_case is easier to read and it's python style. I changed from camelCase to snake_case and i live quiter ;)
Reply all
Reply to author
Forward
0 new messages