Currently, all the fields of the model are serialized by default. It is possible to restrict the direction of the serialization with the Field parameters load_only and dump_only.
There is a hack to get a field ignored by setting both load_only and dump_only to true.
class MySerializer(ModelSerializer):
field_to_ignore = Field(load_only=True, dump_only=True)
But would be nice to have o more official and elegant way to do it. I had some ideas
Opition 1: Add a new flag to Field to make that field ignored
class MySerializer(ModelSerializer):
field_to_ignore = Field(ignore=True)
Opition 2: add meta information about the fields to ignore
class MySerializer(ModelSerializer):
_ignore_fields_ = ['field_to_ignore', 'another_field_to_ignore']
...
Currently, all the fields of the model are serialized by default. It is possible to restrict the direction of the serialization with the
Fieldparametersload_onlyanddump_only.There is a hack to get a field ignored by setting both
load_onlyanddump_onlyto true.But would be nice to have o more official and elegant way to do it. I had some ideas
Opition 1: Add a new flag to
Fieldto make that field ignoredOpition 2: add meta information about the fields to ignore