-
Notifications
You must be signed in to change notification settings - Fork 263
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
Replace NestedFooSerializer
and brief=True
pattern with DRF built-in Meta.depth
#3042
Comments
What is the impact to plugins and integrators to the schemas as well as things like pynautobot? |
https://www.linkedin.com/pulse/friday-quick-tip-dynamic-depth-serialization-django-rest-neidinger is probably relevant as far as dynamic depth based on request query parameters. One thing we might lose in making this change (and should seek to preserve) is the ability to identify related objects by natural keys or otherwise by properties other than PK, e.g.:
instead of requiring:
|
This is writable nested serialization, which I think could still be supported. See: https://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations |
I think we should still marry this with other work to provide PK or Natural Key across the board as best we can. There are some other options here to consider as well. See: |
I may be misunderstanding but that seems different - that seems to be about e.g. creating the nested-serialized objects when creating the base object (although that's also a cool idea!), whereas what we have currently is the ability to reference existing nested-serialized objects by their natural key(s). |
We can do both in fact. Being able to support nested retrieval and updates using either primary keys, natural keys, or nested representations. |
Done with #3500 |
Proposed Changes
The proposed change is:
nested_serializers
modules andNestedFooSerializer
classes?brief=True
and settingself.brief
on viewsetsfoo = NestedFooSerializer()
fields on API serializers and allow them to fall back to the default field from the modeldepth=0
is default (showing PKs),depth=1
shows first-level objects nested representations, etc./api/dcim/sites/?depth=1
)Justification
This bespoke implementation is hindering our ability to leverage existing community extensions to Django for things like JSON schema generation, API import/export using CSV, among others. Additionally it is extra boilerplate code that must be written for each new model, and is custom code that must continue to be maintained and tested.
We will be better off in the long run 1.) using existing features of DRF, 2.) leveraging community resources where reasonably possible.
The text was updated successfully, but these errors were encountered: