Skip to content

Commit

Permalink
Merge pull request #717 from MilanPecov/add-support-for-timezone-field
Browse files Browse the repository at this point in the history
add support for working with pytz object field
  • Loading branch information
JoelLefkowitz authored Jul 18, 2022
2 parents f87dbd5 + 4289361 commit 13f0af2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import OrderedDict
from decimal import Decimal

import pytz
from django.db import models
from django.utils.encoding import force_str
from rest_framework import serializers, status
Expand Down Expand Up @@ -465,6 +466,9 @@ def field_value_to_representation(field, value):
else:
value = str(value)

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

# JSON roundtrip ensures that the value is valid JSON;
# for example, sets and tuples get transformed into lists
return json.loads(json.dumps(value, cls=encoders.JSONEncoder))
Expand Down

0 comments on commit 13f0af2

Please sign in to comment.