dabapps / django-rest-framework-serialization-spec

DEPRECATED, see https://github.com/dabapps/django-readers instead
MIT License
11 stars 0 forks source link

Implement `Aliased` for fields #55

Closed pmg103 closed 3 years ago

pmg103 commented 4 years ago

There is a plugin called Aliased in case you want to rename a field:

serialization_spec = [
  'id',
  'name',
  {'kittehs': Aliased('cats', [
    'name'
  ]}
]

However there’s been an oversight — you can only alias a nested relation like that, not a basic field:

serialization_spec = [
  'id',
  {'title', Aliased('name')},  # DOESN'T WORK
]

For the sake of orthoginality, this form of Aliased, that takes only one argument and renames a field, should be implemented as expected.