Fields with source from related model not inheriting model field properties #9048
Unanswered
mschoettle
asked this question in
Question & Answer
Replies: 1 comment
-
You can use the class FooSerializer(serializers.ModelSerializer):
class Meta:
model = Foo
fields = ['id', 'some_field', 'bar_field']
extra_kwargs = {'bar_field': {'source': 'bar.bar_field'}} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I just realized that when using a
ModelSerializer
and adding additional fields from related models directly as fields by specifying thesource
argument on a field, the field does not inherit the field properties as regular fields for models do.For example
The serializer field for
some_field
hasmax_length=100
whereasbar_field
does not "inherit" the properties fromBar.bar_field
.I understand that the intended way is to use a nested serializer. I am wondering though if there is a way to achieve this with fields specifying the
source
argument.Beta Was this translation helpful? Give feedback.
All reactions