#21300: Allow DateTimeField to return a naive datetime -------------------------------------+------------------------------------- Reporter: brycegroff | Owner: aaugustin Type: New feature | Status: assigned Component: Forms | Version: master Severity: Normal | Resolution: Keywords: forms DateTimeField | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by aaugustin): The main problem in practice is... the global `USE_TZ` setting :( How surprising. For instance, when using PostgreSQL, `DateTimeField`s return aware datetimes because database cursors are configured to add time zone information to all datetimes: {{{ def create_cursor(self): cursor = self.connection.cursor() cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None return cursor }}} ---- Of course, there's a good reasons for making `USE_TZ` global: the template, form and model layers must agree on the mode (naive or aware) in which Django is running. But it could be useful to provide a way to work with naive datetimes in the database and form layers. The template layer already provides a sufficient API. That would require: - a way to override `TIME_ZONE` and `USE_TZ` on a per-database basis. Currently it's already possible, although undocumented, to override `TIME_ZONE`. - a way to override `USE_TZ` in model and form`DateField` and `DateTimeField` on a per-field basis. This would be documented as an advanced use case and it would be up to each project that takes advantage of this to ensure that the right models are used on the right databases. In practice, the main use case is to access third-party databases that store date times in an way that's incompatible with the main project settings. -- Ticket URL: <https://code.djangoproject.com/ticket/21300#comment:11> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.fd5e7414bfdcdb72c75e05c573b799b9%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.