Kirill
Kirill

Reputation: 95

How to use different timezone with Django channels?

How to use different timezone with subscriptions? i have middleware

class TimezoneMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        user = request.UserOrError.user
        user_location = user.get_active_location if hasattr(user, "locations") else None
        if user_location and user_location.time_zone:
            user_timezone = pytz.timezone(user_location.time_zone)
            timezone.activate(user_timezone)
        return self.get_response(request)

@strawberry_django.field()
    def date_created(self, info: Info) -> datetime:
        return self.date_created

but it doesn't work for channels, I get the same time for all countries. How to activate a time zone for each country for subscriptions?

Upvotes: 0

Views: 20

Answers (0)

Related Questions