Skip to content

Add an official way to ignore model fields #26

@lvoliveira

Description

@lvoliveira

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']
   
   ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions