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

Add capability to camelize QuerySets #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion djangorestframework_camel_case/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from collections import OrderedDict
import re

from django.db.models import QuerySet

first_cap_re = re.compile('(.)([A-Z][a-z]+)')
all_cap_re = re.compile('([a-z0-9])([A-Z])')

Expand All @@ -20,6 +22,11 @@ def camelize(data):
for i in range(len(data)):
data[i] = camelize(data[i])
return data
if isinstance(data, QuerySet):
new_list = []
for i in range(len(data)):
new_list.append(camelize(data[i]))
return new_list
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t this the same as return [camelize(item) for item in queryset]?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merwok yes, of course

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that this line was inspired by line 21/23 above, where the existing list is modified in place (which is broken for tuples, debatable for lists and already discussed in other tickets).

return data


Expand All @@ -39,4 +46,4 @@ def underscoreize(data):
for i in range(len(data)):
data[i] = underscoreize(data[i])
return data
return data
return data