You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to be able to set your preferred timezone in the settings page. I wouldn't have noticed its absence without the nice, new View bookmark modal!
I implemented a timezone picker in Cassette Nest (also a Django app) something like this:
frompytzimportcommon_timezones# ... other stuffMIDDLEWARE= [
"your_app.middleware.TimezoneMiddleware",
]
# ... other stuffTIME_ZONES= [(tz, tz) fortzincommon_timezones]
⭐ Create the timezone middleware:
importpytzfromdjango.utilsimporttimezonefromdjango.confimportsettingsclassTimezoneMiddleware:
""" Automatically set the timezone to what's set on the User's profile. """def__init__(self, get_response):
self.get_response=get_responsedef__call__(self, request):
ifrequest.user.is_authenticated:
try:
tzname=request.user.profile.timezoneiftzname:
timezone.activate(pytz.timezone(tzname))
else:
timezone.activate(pytz.timezone(settings.TIME_ZONE))
exceptProfile.DoesNotExist:
timezone.activate(pytz.timezone(settings.TIME_ZONE))
else:
timezone.deactivate()
returnself.get_response(request)
⭐ Add this to my profile model:
fromdjango.confimportsettings# other stuff ...timezone=models.CharField(
max_length=40,
blank=True,
choices=settings.TIME_ZONES,
default=settings.TIME_ZONE,
)
⭐ And add the field to the ModelForm.
I'd be happy to help implement this if you want it done! 😄
I should note that my user profile model is just called Profile, but that's a minor difference.
The text was updated successfully, but these errors were encountered:
It would be nice to be able to set your preferred timezone in the settings page. I wouldn't have noticed its absence without the nice, new View bookmark modal!
I implemented a timezone picker in Cassette Nest (also a Django app) something like this:
⭐ Install
pytz
⭐ Add some things to
settings.py
:⭐ Create the timezone middleware:
⭐ Add this to my profile model:
⭐ And add the field to the
ModelForm
.I'd be happy to help implement this if you want it done! 😄
I should note that my user profile model is just called
Profile
, but that's a minor difference.The text was updated successfully, but these errors were encountered: