Equivalent of Pydantic __root__
attribute
#8851
Unanswered
johnthagen
asked this question in
Ideas & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a
Serializer
that I would like to contain some data directly without an attribute name. Pydantic has this feature using the__root__
special attribute:And example of this data would be:
This can be very nice when you want to express (and then have an automatic OpenAPI description for) root types.
With DRF, as far as I've been able to find, this isn't possible and you would need to name that field. I've found some hacks, but nothing that seems declarative in a way that other tools, such as
drf-spectacular
could take ahold of:Does DRF have an equivalent way to model this kind of data?
Beta Was this translation helpful? Give feedback.
All reactions