Skip to content

Commit

Permalink
Fix JSON export trailing comma (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrendel authored Oct 24, 2024
1 parent e5e366b commit e2f84cc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sqladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,16 @@ def formatter(model, attribute):
Normally, objects have three save options:
``Save`, `Save and continue editing` and `Save and add another`.
If save_as is True, `Save and add another` will be replaced
by a `Save as new` button
that creates a new object (with a new ID)
If save_as is True, `Save and add another` will be replaced
by a `Save as new` button
that creates a new object (with a new ID)
rather than updating the existing object.
By default, `save_as` is set to `False`.
"""

save_as_continue: ClassVar[bool] = True
"""When `save_as=True`, the default redirect after saving the new object
"""When `save_as=True`, the default redirect after saving the new object
is to the edit view for that object.
If you set `save_as_continue=False`, the redirect will be to the list view.
Expand Down Expand Up @@ -1194,14 +1194,16 @@ async def _export_json(
) -> StreamingResponse:
async def generate() -> AsyncGenerator[str, None]:
yield "["
separator = "," if len(data) > 1 else ""
len_data = len(data)
last_idx = len_data - 1
separator = "," if len_data > 1 else ""

for row in data:
for idx, row in enumerate(data):
row_dict = {
name: str(await self.get_prop_value(row, name))
for name in self._export_prop_names
}
yield json.dumps(row_dict) + separator
yield json.dumps(row_dict) + (separator if idx < last_idx else "")

yield "]"

Expand Down

0 comments on commit e2f84cc

Please sign in to comment.