-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Serializer mixin fields not getting picked up #4482
Comments
Fields are gathered on classes that inherit from serializers. |
Ok, see |
Should likely do the trick |
It does:
I more asking if this from a framework design perspective is ok or if the meta class is considered internal. |
The metaclass is considered as internal since it's not documented. However, it's unlikely to change. |
Why do @six.add_metaclass(serializers.SerializerMetaclass)
class MyMixin(object): when you can just do class MyMixin(serializers.Serializer): especially since the former is not technically a public API? Is there something I'm missing? |
I'm using this for both |
Using Serializer instead of just the meta may mess with heritage if some intermediate mixins do override some members. |
I know one thing that could be problematic when inheriting |
Hello, I know there's quite a gap between when this issue has been handled, but referencing what @vesterbaek suggested in his test case:
Is this still the way to go if we want to make generic fields or groups of fields that we want to reuse across different serializers with specific settings that implement the same logic based on these given fields @xordoquy ? Is doing this good practice, even if not documented ? Else, is there another way to declaring serializers that is similar to the way DRF views are composable with mixins ? I would also like to do this for Django Models, but that is not in the scope of DRF thus i won't focus on it here, but i think the way to do it is django models with abstract = True to illustrate, let me show what i mean by showing the piece of logic i want implement based on @vesterbaek 's code:
I want to use this logic across multiple serializers/models , is this suitable ? / doable in any other way ? / not possible ? Thanks in advance, Hope someone can answer despite the multiple year gap between comments :) |
I would like to declare som common fields in a mixin class, used by subclasses of both
serializer.Serializer
andserializer.ModelSerializer
. These fields, however, seems not to be picked up, even though defined inMeta.fields
. Is this by design?Repro:
=>
The text was updated successfully, but these errors were encountered: