Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#23971 closed New feature (fixed)

Allow list filter filtering of None on null date fields

Reported by: Ryno Owned by: Ryno
Component: contrib.admin Version: dev
Severity: Normal Keywords: filter, admin
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently I'm overriding the DateFieldListFilter, but I think it should possibly be in Django?

# Override Datefield filter (add None)
from django.contrib.admin.filters import FieldListFilter, DateFieldListFilter

class DateFieldListFilter(DateFieldListFilter):
    def __init__(self, field, request, params, model, model_admin, field_path):
        super(DateFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path)
        if field.null:
            self.links += (
                (_('None'), {
                    self.field_generic + 'isnull': str(True),
                }),
                (_('Not None'), {
                    self.field_generic + 'isnull': str(False),
                }),
            )

FieldListFilter.register(                                                                                                                             
    lambda f: isinstance(f, models.DateField), DateFieldListFilter, True)

Change History (14)

comment:2 by Ryno, 9 years ago

Owner: changed from nobody to Ryno
Status: newassigned

comment:3 by Ryno, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:4 by Tim Graham, 9 years ago

Has patch: set
Resolution: fixed
Status: closednew

Ticket is not fixed until code is merged.

comment:5 by Tim Graham, 9 years ago

Easy pickings: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

This seems okay, although it might make the UI a bit confusing because the distinction between 'Any date' and 'Has date' isn't so clear.

The patch can be cleaned up a bit if you work through our patch review checklist.

comment:6 by Ryno, 9 years ago

Thanks timgraham, sorry I thought I would get a notification or something about this... will clean it up

comment:7 by Ryno, 8 years ago

Status: newassigned

comment:8 by Ryno, 8 years ago

I've reworded a bit it, I hope that looks better?
I looked at the guidelines, and I can't really find a fault?
I'll be happy to clean it up. Maybe I should change it a bit, and have

self.lookup_kwarg_isnull = '%s__isnull' % field_path

comment:9 by Tim Graham, 8 years ago

Patch needs improvement: unset

comment:10 by Tim Graham, 8 years ago

Summary: Allow filtering of None on null date fieldsAllow list filter filtering of None on null date fields
Triage Stage: AcceptedReady for checkin

comment:11 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 468d8211:

Fixed #23971 -- Added "Has date"/"No date" choices for DateFieldListFilter.

in reply to:  11 comment:12 by Ryno, 8 years ago

Replying to Tim Graham <timograham@…>:

In 468d8211:

Fixed #23971 -- Added "Has date"/"No date" choices for DateFieldListFilter.

I just thought I'd bring up a previous comment, about clearer distinction:

Replying to timgraham:

This seems okay, although it might make the UI a bit confusing because the distinction between 'Any date' and 'Has date' isn't so clear.

The patch can be cleaned up a bit if you work through our patch review checklist.

That's the main reason I went for Has valid date.

comment:13 by Tim Graham, 8 years ago

Oh, "Has valid date" left me wondering how/if something could have an "invalid" date.

in reply to:  13 comment:14 by Ryno, 8 years ago

Replying to timgraham:

Oh, "Has valid date" left me wondering how/if something could have an "invalid" date.

Oic :) thanks Tim!

Note: See TracTickets for help on using tickets.
Back to Top