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:
shrajal01 2025-11-12 01:55:52 +05:30 committed by GitHub
parent 7166a78520
commit 8fa867aeb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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):