#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------+--------------------------------------
     Reporter:  john-parton    |                    Owner:  (none)
         Type:  Bug            |                   Status:  new
    Component:  contrib.admin  |                  Version:  5.0
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  1              |      Needs documentation:  1
  Needs tests:  1              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Changes (by john-parton):

 * has_patch:  0 => 1
 * needs_docs:  0 => 1
 * needs_tests:  0 => 1


Old description:

> If you have a GeneratedField with output_field set to DateField or
> DateTimeField, you cannot use it in the admin as a `date_hierarchy`
> because of a check. If you skip the check, it actually works just fine in
> my testing. I believe this the check could be adjusted to account for
> this.
>

> {{{
> # models.py
> class TestModel(models.Model):
>     date_range = DateTimeRangeField(_("Date range"))
>     start_date = models.GeneratedField(
>         expression=Lower("date_range"),
>         output_field=models.DateTimeField(),
>         db_persist=True,
>     )
>

>
> # admin.py
> class TestAdmin(admin.ModelAdmin):
>     date_hierarchy = "start_date"
>
>     # Skipping checks actually makes this work exactly correctly
>     def check(self, *args, **kwargs):
>         return ()
>
> }}}
>
> I'll see if I can whip up a patch.

New description:

 If you have a GeneratedField with output_field set to DateField or
 DateTimeField, you cannot use it in the admin as a `date_hierarchy`
 because of a check. If you skip the check, it actually works just fine in
 my testing. I believe this the check could be adjusted to account for
 this.


 {{{
 # models.py
 class TestModel(models.Model):
     date_range = DateTimeRangeField(_("Date range"))
     start_date = models.GeneratedField(
         expression=Lower("date_range"),
         output_field=models.DateTimeField(),
         db_persist=True,
     )



 # admin.py
 class TestAdmin(admin.ModelAdmin):
     date_hierarchy = "start_date"

     # Skipping checks actually makes this work exactly correctly
     def check(self, *args, **kwargs):
         return ()

 }}}

 I'll see if I can whip up a patch.

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35628#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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070190e61cfdb3-7e5bba55-cc3e-4d21-beb4-edd0f35397b5-000000%40eu-central-1.amazonses.com.

Reply via email to