#27186: Cannot change DateTimeField with default via Admin since Django 1.10.1 -------------------------------+-------------------------------------- Reporter: michael-k | Owner: nobody Type: Uncategorized | Status: new Component: Forms | Version: 1.10 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Changes (by michael-k):
* needs_better_patch: => 0 * needs_tests: => 0 * needs_docs: => 0 Old description: > Since Django 1.10.1 (it worked in 1.10.0), it is not possible to change > the value of a DateTimeField in the admin if the field has a default. > > Changing the value and saving the object results in the old value still > being in the database. > > == How to reproduce == > > I created a small [https://github.com/michael-k/datetimefieldbroken > example project] to easily reproduce the problem. > > It has a > [https://github.com/michael-k/datetimefieldbroken/blob/b6ff942dd328007bf4af199b91d20d6cbfbb09d5/datetimefieldbroken/main/models.py#L5-L7 > model ''Dummy''] with two DateTimeFields. One ''with'' and one > ''without'' a default (''django.utils.timezone.now''). The > [https://github.com/michael-k/datetimefieldbroken/blob/b6ff942dd328007bf4af199b91d20d6cbfbb09d5/datetimefieldbroken/main/admin.py#L6-L8 > admin] is the default ''django.contrib.admin.ModelAdmin''. > > {{{ > git clone https://github.com/michael-k/datetimefieldbroken.git && cd > datetimefieldbroken > docker-compose build --pull > docker-compose run web migrate > docker-compose run web createsuperuser > docker-compose up -d > }}} > > Head your browser to [http://localhost:8023/admin/main/dummy/add/], login > and create a new ''Dummy'' using ''Save and continue editing''. Change > the values all for input fields and press ''Save and continue editing'' > again. The values of ''Dt with default'' are unchanged. > > > == Patch that introduced the issue == > > We belive that [https://github.com/django/django/pull/7195/files PR 7195] > (redaring [https://code.djangoproject.com/ticket/27039 issue 27039]) > introduced the problem, but did not validate this. Supposedly this > happens because DateTimeField is split into two fields (date + time) in > the admin. > > We tried it however with Django 1.10.0 and it works just fine. New description: Since Django 1.10.1 (it worked in 1.10.0), it is not possible to change the value of a DateTimeField in the admin if the field has a default. Changing the value and saving the object results in the old value still being in the database. == How to reproduce == I created a small [https://github.com/michael-k/datetimefieldbroken example project] to easily reproduce the problem. It has a [https://github.com/michael-k/datetimefieldbroken/blob/b6ff942dd328007bf4af199b91d20d6cbfbb09d5/datetimefieldbroken/main/models.py#L5-L7 model ''Dummy''] with two DateTimeFields. One ''with'' and one ''without'' a default (''django.utils.timezone.now''). The [https://github.com/michael-k/datetimefieldbroken/blob/b6ff942dd328007bf4af199b91d20d6cbfbb09d5/datetimefieldbroken/main/admin.py#L6-L8 admin] is the default ''django.contrib.admin.ModelAdmin''. {{{ git clone https://github.com/michael-k/datetimefieldbroken.git && cd datetimefieldbroken docker-compose build --pull docker-compose run web migrate docker-compose run web createsuperuser docker-compose up -d }}} Head your browser to [http://localhost:8023/admin/main/dummy/add/], login and create a new ''Dummy'' using ''Save and continue editing''. Change the values all for input fields and press ''Save and continue editing'' again. The values of ''Dt with default'' are unchanged. == Patch that introduced the issue == We belive that [https://github.com/django/django/pull/7068 PR 7068] (regarding [https://code.djangoproject.com/ticket/27039 issue 27039]) introduced the problem, but did not validate this. Supposedly this happens because DateTimeField is split into two fields (date + time) in the admin. We tried it however with Django 1.10.0 and it works just fine. -- -- Ticket URL: <https://code.djangoproject.com/ticket/27186#comment:1> 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/067.0044dc196f4e0982eff02a8584e96184%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.