Skip to content

Commit

Permalink
Add support for working with zoneinfo object field
Browse files Browse the repository at this point in the history
  • Loading branch information
nikvst committed Dec 5, 2023
1 parent afea1bc commit 0c73a90
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

from .app_settings import swagger_settings

try:
import zoneinfo
except ImportError:
try:
from backports import zoneinfo
except ImportError:
zoneinfo = None


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -465,7 +474,10 @@ def field_value_to_representation(field, value):
else:
value = str(value)

if isinstance(value, pytz.BaseTzInfo):
elif isinstance(value, pytz.BaseTzInfo):
value = str(value)

elif zoneinfo is not None and isinstance(value, zoneinfo.ZoneInfo):
value = str(value)

# JSON roundtrip ensures that the value is valid JSON;
Expand Down

0 comments on commit 0c73a90

Please sign in to comment.