Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from kleinron/master
Browse files Browse the repository at this point in the history
typo + code reuse
  • Loading branch information
amitnabarro committed Oct 17, 2017
2 parents 5e174c5 + 87d95d2 commit 8c1629a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/source/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Serialization

Models are responsible not only for declaring a schema and validating the data, but also for serializing the models to useful data structures.
Controlling the way data models are serialized is extremely useful when creating APIs.
More often than not, the application's requirements dicate cases other than a straightforward one-to-one mapping between the data attributes of a model and the API.
More often than not, the application's requirements dictate cases other than a straightforward one-to-one mapping between the data attributes of a model and the API.
In some cases there may be a need to omit some data, which is meant only for internal use and not for API consumption.
In other cases there may be additional data attributes, required as part of an API endpoint, which are a result of a calculation, aggregation, or data manipulation between 1 or more data attributes.

Expand Down
5 changes: 3 additions & 2 deletions tbone/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ def _convert(self, data, native):
converted_data = {}
for name, field in self._fields.items():
if native is True:
converted_data[name] = field.to_python(data.get(name))
conversion_func = field.to_python
else:
converted_data[name] = field.to_data(data.get(name))
conversion_func = field.to_data
converted_data[name] = conversion_func(data.get(name))
return converted_data

def import_data(self, data: dict):
Expand Down

0 comments on commit 8c1629a

Please sign in to comment.