mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-12-26 19:42:55 +03:00
Refactor get_initial for list input handlingFix ListSerializer.get_initial to return consistent initial list structure
Modify get_initial to return a consistent list format when initial_data is a list.
This commit is contained in:
parent
365d409adb
commit
7166a78520
|
|
@ -608,10 +608,15 @@ class ListSerializer(BaseSerializer):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.child.bind(field_name='', parent=self)
|
||||
|
||||
def get_initial(self):
|
||||
if hasattr(self, 'initial_data'):
|
||||
return self.to_representation(self.initial_data)
|
||||
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]
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
def get_value(self, dictionary):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user