File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 77from schema .QuadrupoleElement import QuadrupoleElement
88
99
10- class Line (BaseModel ):
10+ class Line (BaseElement ):
1111 """A line of elements and/or other lines"""
1212
1313 # Validate every time a new value is assigned to an attribute,
@@ -67,17 +67,17 @@ def parse_list_of_dicts(cls, value):
6767
6868 def model_dump (self , * args , ** kwargs ):
6969 """This makes sure the element name property is moved out and up to a one-key dictionary"""
70- # Use default dump for non-line fields
70+ # Use base element dump first and return a one-element list of the form
71+ # [{key: value}], where 'key' is the name of the line and 'value' is a
72+ # dictionary with all other properties
7173 data = super ().model_dump (* args , ** kwargs )
72-
7374 # Reformat 'line' field as list of single-key dicts
7475 new_line = []
7576 for elem in self .line :
7677 # Use custom dump for each line element
7778 elem_dict = elem .model_dump (** kwargs )[0 ]
7879 new_line .append (elem_dict )
79-
80- data ["line" ] = new_line
80+ data [0 ][self .name ]["line" ] = new_line
8181 return data
8282
8383
You can’t perform that action at this time.
0 commit comments