Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting to preserve _leadingUnderscores #53

Open
rorybyrne opened this issue Mar 27, 2019 · 2 comments
Open

Setting to preserve _leadingUnderscores #53

rorybyrne opened this issue Mar 27, 2019 · 2 comments

Comments

@rorybyrne
Copy link

rorybyrne commented Mar 27, 2019

Hi folks, in my API I have some keys with _leading_underscores, for example:

{
    '_str': 'String',
    '_timestamp': 1234567890,
    'firstValue': '...',
    'secondValue: '...'
}

I want to preserve these leading _'s, but camelize the other fields.

I am thinking about a PR that adds a setting PRESERVE_LEADING_UNDERSCORE, which would allow camelize_re in utils.py to be [a-z0-9]_[a-z0-9] instead of [a-z0-9]?_[a-z0-9] - note the changed '?'.

This would probably involve changing camelize_re from being a constant to being generated by a utils.py function, perhaps get_camelize_re().

Thoughts?

@snowman2
Copy link

I would like to add my vote +1 to this idea.

@pxotox
Copy link

pxotox commented Jul 8, 2021

Until this is not added, a workaround is to override camelize_re regex. Adding the following code to the settings file works

import re
from djangorestframework_camel_case import util
util.camelize_re = re.compile(r"[a-z0-9]_[a-z0-9]")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants