Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/application/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@desc:
"""
import datetime
import decimal
import json
import uuid

Expand Down Expand Up @@ -140,6 +141,8 @@ def default(self, obj):
return str(obj)
if isinstance(obj, datetime.datetime):
return obj.strftime("%Y-%m-%d %H:%M:%S")
if isinstance(obj, decimal.Decimal):
return float(obj)
else:
return json.JSONEncoder.default(self, obj)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No significant issues were found in the provided code. However, there is a minor suggestion for improvement:

+        if isinstance(obj, decimal.Decimal):
+# Use float() to convert Decimal instead of str()
+            return float(obj)

This change ensures that when decimal.Decimal objects are encountered during serialization, they are converted to a floating-point number rather than converting them to strings. This might be more suitable depending on how you want to store or manipulate these numbers later in your application.

Expand Down