Skip to content
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
18 changes: 11 additions & 7 deletions rest_witchcraft/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def is_nested(self):

def build_standard_field_kwargs(self, field_name, field_class, column_info):
"""Analyze model column to generate field kwargs."""
field_kwargs = column_info.field_kwargs.copy()
field_kwargs = copy.deepcopy(column_info.field_kwargs)
field_kwargs["label"] = capfirst(" ".join(field_name.split("_")).strip())
field_kwargs["allow_null"] = not field_kwargs.get("required", True)

Expand Down Expand Up @@ -383,13 +383,16 @@ def get_field_names(self, declared_fields, info):
serializer_class=self.__class__.__name__
)

assert not (_fields is None and exclude is None), (
assert _fields is not None or exclude is not None, (
"Creating a ModelSerializer without either the 'fields' attribute "
"or the 'exclude' attribute has been deprecated since 3.3.0, "
"and is now disallowed. Add an explicit fields = '__all__' to the "
"{serializer_class} serializer.".format(serializer_class=self.__class__.__name__),
"{serializer_class} serializer.".format(
serializer_class=self.__class__.__name__
),
)

Comment on lines -386 to 394
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelSerializer.get_field_names refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)


if _fields == ALL_FIELDS:
_fields = None

Expand Down Expand Up @@ -574,10 +577,11 @@ def get_nested_relationship_fields(self, relation_info, depth):
target_model_info = meta.model_info(relation_info.related_model)

# figure out backrefs
backrefs = set()
for key, rel in target_model_info.relationships.items():
if rel.related_model == self.model:
backrefs.add(key)
backrefs = {
key
for key, rel in target_model_info.relationships.items()
if rel.related_model == self.model
}
Comment on lines -577 to +584
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelSerializer.get_nested_relationship_fields refactored with the following changes:


_fields = set(target_model_info.primary_keys.keys())
_fields.update(target_model_info.properties.keys())
Expand Down