-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add an official way to ignore model fields #26
Comments
The "read-only", "write-only", and "ignore" are actually the same option, as the hack "load_only=True/dump_only=True" suggests. How about: class MySerializer(ModelSerializer):
field = Field(mode="load-only") With mode being |
Sounds reasonable, since this would solve the inconsistency of having more the one of this options set to Another option would be to have specific field classes for each of these behaviors class MySerializer(ModelSerializer):
dump_only_field = DumpField()
load_only_field = LoadField()
field_to_ignore = IgnoreField() |
Indeed. The mode however gives the possibility to include more options in the future. Well let's see what @igortg has to say. 👍 |
I personally think it's reasonable to have a It's simple to check the function interface and if I see this option, I automatically think the field with it will not be serialized either way. It even comes with the plus of being easier to implement. |
Maybe we can fix that by solving a bad architectural decision (IMHO) we did when creating the library: by default, My suggestion is changing the default behavior of This would not completely solve the problem... we may still have to set Please, feel free to argue that I'm going "to far from the scope". |
@igortg I agree with you, but as you spotted out, your solution may not solve the problem of the |
Agree with @lvoliveira and @nobreconfrade. ignore=True|False (default=False) would be enough. @igortg explicit declare a field to ignored is good IMHO, first when not declared warnings are thrown (it is a sign you forgot something)... and to say explicitly to ignore you know what you are doing. @nicoddemus I doubt it will have more modes. Write only, read only, both or None. |
Ok. So you can go with the simplest solution: |
Currently, all the fields of the model are serialized by default. It is possible to restrict the direction of the serialization with the
Field
parametersload_only
anddump_only
.There is a hack to get a field ignored by setting both
load_only
anddump_only
to 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 ignoredOpition 2: add meta information about the fields to ignore
The text was updated successfully, but these errors were encountered: