#35628 closed Bug (fixed)
date_hierarchy doesn't support GenerateField with output_field set to DateTimeField or DateField
Description (last modified by ) ¶
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.
Change History (8)
comment:1 by , 8 months ago
Description: | modified (diff) |
---|---|
Has patch: | set |
Needs documentation: | set |
Needs tests: | set |
comment:2 by , 8 months ago
comment:3 by , 8 months ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 8 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:5 by , 7 months ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Triage Stage: | Accepted → Ready for checkin |
Waiting for a final OK from Simon.
Note:
See TracTickets
for help on using tickets.
Initial patch here: https://github.com/django/django/pull/18407
No docs or tests yet.