mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-12-04 16:54:02 +03:00
Fix indentation and implementation of get_initial in ListSerializer
Corrected the get_initial method to return consistent list format and fixed indentation to avoid SyntaxError / IndentationError in tests.
This commit is contained in:
parent
7166a78520
commit
8fa867aeb6
|
|
@ -609,15 +609,18 @@ class ListSerializer(BaseSerializer):
|
||||||
self.child.bind(field_name='', parent=self)
|
self.child.bind(field_name='', parent=self)
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
"""
|
||||||
|
Return a list of initial values, one for each item in `initial_data`,
|
||||||
|
or an empty list if no input data was provided.
|
||||||
|
"""
|
||||||
if hasattr(self, 'initial_data'):
|
if hasattr(self, 'initial_data'):
|
||||||
# If data is given, we should just return the raw input structure,
|
|
||||||
# but ensure it's represented in a consistent list format.
|
|
||||||
if isinstance(self.initial_data, list):
|
if isinstance(self.initial_data, list):
|
||||||
return [self.child.get_initial() for _ in self.initial_data]
|
return [self.child.get_initial() for _ in self.initial_data]
|
||||||
return []
|
return []
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_value(self, dictionary):
|
def get_value(self, dictionary):
|
||||||
"""
|
"""
|
||||||
Given the input dictionary, return the field value.
|
Given the input dictionary, return the field value.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user