mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-25 19:43:47 +03:00
Update serializers.py
Prevent iterating over a string that is supposed to be an iterable <==> Prevent read_only_fields = ('some_string)
This commit is contained in:
parent
24a6882232
commit
5c87db96c5
|
@ -758,6 +758,9 @@ class ModelSerializer(Serializer):
|
||||||
|
|
||||||
ret[accessor_name] = field
|
ret[accessor_name] = field
|
||||||
|
|
||||||
|
#Ensure that 'read_only_fields is an iterable
|
||||||
|
assert isinstance(self.opts.read_only_fields, (list, tuple)), '`read_only_fields` must be a list or tuple'
|
||||||
|
|
||||||
# Add the `read_only` flag to any fields that have bee specified
|
# Add the `read_only` flag to any fields that have bee specified
|
||||||
# in the `read_only_fields` option
|
# in the `read_only_fields` option
|
||||||
for field_name in self.opts.read_only_fields:
|
for field_name in self.opts.read_only_fields:
|
||||||
|
@ -772,6 +775,9 @@ class ModelSerializer(Serializer):
|
||||||
(field_name, self.__class__.__name__))
|
(field_name, self.__class__.__name__))
|
||||||
ret[field_name].read_only = True
|
ret[field_name].read_only = True
|
||||||
|
|
||||||
|
# Ensure that 'write_only_fields' is an iterabe
|
||||||
|
assert isinstance(self.opts.write_only_fields, (list, tuple)), '`read_only_fields` must be a list or tuple'
|
||||||
|
|
||||||
for field_name in self.opts.write_only_fields:
|
for field_name in self.opts.write_only_fields:
|
||||||
assert field_name not in self.base_fields.keys(), (
|
assert field_name not in self.base_fields.keys(), (
|
||||||
"field '%s' on serializer '%s' specified in "
|
"field '%s' on serializer '%s' specified in "
|
||||||
|
|
Loading…
Reference in New Issue
Block a user