mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
Merge pull request #4688 from theosotr/feature-source
Support usage of 'source' in `extra_kwargs`.
This commit is contained in:
commit
2df80c3c9d
|
@ -999,13 +999,15 @@ class ModelSerializer(Serializer):
|
||||||
fields[field_name] = declared_fields[field_name]
|
fields[field_name] = declared_fields[field_name]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
extra_field_kwargs = extra_kwargs.get(field_name, {})
|
||||||
|
source = extra_field_kwargs.get('source') or field_name
|
||||||
|
|
||||||
# Determine the serializer field class and keyword arguments.
|
# Determine the serializer field class and keyword arguments.
|
||||||
field_class, field_kwargs = self.build_field(
|
field_class, field_kwargs = self.build_field(
|
||||||
field_name, info, model, depth
|
source, info, model, depth
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include any kwargs defined in `Meta.extra_kwargs`
|
# Include any kwargs defined in `Meta.extra_kwargs`
|
||||||
extra_field_kwargs = extra_kwargs.get(field_name, {})
|
|
||||||
field_kwargs = self.include_extra_kwargs(
|
field_kwargs = self.include_extra_kwargs(
|
||||||
field_kwargs, extra_field_kwargs
|
field_kwargs, extra_field_kwargs
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user