2

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 posted, 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 and post 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.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
GeoH
  • 63
  • 4
  • Yes, this is basically a question about Django's generic class-based views, and this kind of confusion is exactly why they are so controversial. Unfortunately I don't have any insight into that, good luck. – Kevin Christopher Henry Jul 12 '20 at 07:37

0 Answers0