[Django]-Serialize Timezone Object

3👍

I ended up making a custom serializer field and using the zone field on the timezone object.

class TimezoneField(Field):
    "Take the timezone object and make it JSON serializable"
    def to_representation(self, obj):
        return obj.zone

    def to_internal_value(self, data):
        return data

class AppSettingsSerializer(ModelSerializer):

    timezone = TimezoneField()

    class Meta:
        model = UserAppSettings

Leave a comment