You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
Made a small snippet for serializing relatedmanager objects (lazily sadly).
from marshmallow import ValidationError
from marshmallow.fields import Nested
class RelatedNested(Nested):
def _serialize(self, nested_obj, attr, obj, **kwargs):
# Load up the schema first. This allows a RegistryError to be raised
# if an invalid schema name was passed
schema = self.schema
if nested_obj is None:
return None
try:
return schema.dump(getattr(obj, attr).all(), many=self.many)
except ValidationError as exc:
raise ValidationError(exc.messages, valid_data=exc.valid_data) from exc
Any advice on whether using the obj directly is the right way?
The text was updated successfully, but these errors were encountered:
davidzwa
changed the title
RelatedManager and & FieldNested
RelatedManager and FieldNested
Jul 5, 2019
davidzwa
changed the title
RelatedManager and FieldNested
RelatedManager and Nested field
Jul 5, 2019
Made a small snippet for serializing relatedmanager objects (lazily sadly).
Any advice on whether using the obj directly is the right way?
The text was updated successfully, but these errors were encountered: