I have a model related to real world events that contains both DateTimeField
and Location(PointField
).
The DateTime will always be entered/updated by the user in the TZ of the location (I'll refer to it as local time). Therefore, once the form is post
ed, I need to get the timezone for the location, and apply it to the local DateTime before it is saved to the DB.
As it is an UpdateView, I also need to be able to take an instance stored in the DB and present it to the user in local time in the form when the user get
's the form.
I'm comfortable with getting the timezone for the location, and using Django's timezone to convert the datetime if necessary. However, I'm not sure what the best approach is. The two I have come up with are:
- Use django.utils.timezone's activate(). This seems the most pythonic approach but I'm 70% N00b and can't figure out which method to override in order to ensure the
get
andpost
are both handled correctly. - Override get_context_data() and form_valid(). With this approach I would perform the change from timezone aware datetime to local and back in each method.
Thank you for any help. Eek...it's Saturday Night.