mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-12-04 08:44: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
|
|
@ -608,14 +608,17 @@ class ListSerializer(BaseSerializer):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.child.bind(field_name='', parent=self)
|
||||
|
||||
def get_initial(self):
|
||||
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):
|
||||
return [self.child.get_initial() for _ in self.initial_data]
|
||||
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 isinstance(self.initial_data, list):
|
||||
return [self.child.get_initial() for _ in self.initial_data]
|
||||
return []
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
|
||||
def get_value(self, dictionary):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user