mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
modify _writable_fields in serializers.py
Sometimes 'self' instance is not a field (used in rest_framework) If the 'serializer' that contains 'field' is 'self', only the subelements of the serializer, the 'fields', are returned. in the case of a serializer that contains 'field' as a 'child' element, Only instances of `.source` ending with` _set '(following relationships "backward") are found using regular expressions. Then use the child elements again to find the field using '_writable_fields'. Do not modify '_readable_fields' because it does not address the issue of what is currently being viewed.
This commit is contained in:
parent
238783f2ed
commit
5e7497bfe0
|
@ -362,10 +362,15 @@ class Serializer(BaseSerializer):
|
|||
|
||||
@cached_property
|
||||
def _writable_fields(self):
|
||||
return [
|
||||
field for field in self.fields.values()
|
||||
if (not field.read_only) or (field.default is not empty)
|
||||
]
|
||||
ret = []
|
||||
for field in self.fields.values():
|
||||
if re.compile("\_set$").findall(field.source):
|
||||
for field in field.child._writable_fields:
|
||||
ret.append(field)
|
||||
continue
|
||||
if (not field.read_only) or (field.default is not empty):
|
||||
ret.append(field)
|
||||
return ret
|
||||
|
||||
@cached_property
|
||||
def _readable_fields(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user