[Django] #28687: Not 'Empty' Related Filter option

44 views
Skip to first unread message

Django

unread,
Oct 6, 2017, 8:22:04 AM10/6/17
to django-...@googlegroups.com
#28687: Not 'Empty' Related Filter option
-----------------------------------------------+------------------------
Reporter: Brillgen Developers | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------------+------------------------
Currently the admin related filter has an 'All' and a 'Empty Value' option
...however it does not have an equally easy to implement and performant
NOT 'Empty' option for those cases where we want to filter like that. It
maps cleanly onto isnull = True/False.

Would this be accepted if a patch was added since its rather easy to do
but the core needs to be ok with it first.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 10, 2017, 12:45:19 AM10/10/17
to django-...@googlegroups.com
#28687: Not 'Empty' Related Filter option
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
| Barber
Type: Uncategorized | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jake Barber):

* owner: nobody => Jake Barber
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:1>

Django

unread,
Dec 28, 2017, 11:43:19 AM12/28/17
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter

-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Cleanup/optimization
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

Seems okay at first glance.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:2>

Django

unread,
Apr 26, 2018, 5:01:51 AM4/26/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:3>

Django

unread,
May 3, 2018, 3:56:29 AM5/3/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 1 => 0


Comment:

PR is functionally OK.

It hardcodes a (translatable) "Not Empty" string. I'm not sure if we need
to do something more sophisticated there (or take a different approach,
such as using a filter subclass if you want this behaviour) or if it's OK
as it is.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:4>

Django

unread,
May 3, 2018, 7:22:02 AM5/3/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

As for the display value, it should mimic the
`model_admin.get_empty_value_display()` behavior
(`get_not_empty_value_display()`).

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:5>

Django

unread,
May 10, 2018, 6:18:51 AM5/10/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:6>

Django

unread,
Jun 8, 2018, 2:58:20 AM6/8/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

OK, patch looks good.

I have a small reservation about whether we want yet more API on
ModelAdmin to add the `not_empty_value_display` option, rather than
steering users to subclassing `FieldListFilter` themselves, but bar
that...

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:7>

Django

unread,
Jun 20, 2018, 1:39:37 PM6/20/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1

* stage: Ready for checkin => Accepted


Comment:

I agree -- `get_not_empty_value_display()` looks heavy handed for this use
case. `get_empty_value_display()` is used elsewhere besides the
`RelatedFieldListFilter` and it corresponds to the values displayed in the
changelist -- that's not the case for the "not empty" case.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:8>

Django

unread,
Aug 18, 2018, 4:40:34 PM8/18/18
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: assigned => closed
* resolution: => wontfix


Comment:

After some discussion on the pull request, I think it's better if users
subclass the relevant list filter and add the "not empty" option if they
desire it. It doesn't seem like a particularly common need and that way
it's not cluttering things for everyone else.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:9>

Django

unread,
Jan 11, 2019, 11:50:45 PM1/11/19
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sardorbek Imomaliev):

* status: closed => new
* resolution: wontfix =>


Comment:

I think we should reopen this and fix an issue with current
`RelatedFieldListFilter`. For example currently to add `Not Empty` choice
you need to do this

{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class NotEmptyFilter(admin.RelatedFieldListFilter):
@property
def include_empty_choice(self):
# FIXME: empty value selected incorrectly override in choices
return False

def has_output(self):
return super().has_output() + 2

def choices(self, changelist):
yield from super().choices(changelist)
yield {
'selected': self.lookup_val_isnull == 'True',
'query_string': changelist.get_query_string(
{self.lookup_kwarg_isnull: 'True'}, [self.lookup_kwarg]
),
'display': _('Empty'),
yield {
'selected': self.lookup_val_isnull == 'False',
'query_string': changelist.get_query_string(
{self.lookup_kwarg_isnull: 'False'}, [self.lookup_kwarg]
),
'display': _('Not Empty'),
}
}}}
}}}

But you should be able to do just
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class NotEmptyFilter(admin.RelatedFieldListFilter):
def has_output(self):
return super().has_output() + 1

def choices(self, changelist):
yield from super().choices(changelist)
yield {
'selected': self.lookup_val_isnull == 'False',
'query_string': changelist.get_query_string(
{self.lookup_kwarg_isnull: 'False'}, [self.lookup_kwarg]
),
'display': _('Not Empty'),
}
}}}
}}}

Currently this is not possible because of `bool(self.lookup_val_isnull)`
check in selected for `Empty` choice, and if we add `Not Empty` choice
like in second example we will get both `Empty` and `Not Empty` choices
rendered as selected on `Not Empty`

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:10>

Django

unread,
Jan 16, 2019, 10:55:00 AM1/16/19
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => fixed


Comment:

Hi Sardorbek.

This looks like a (related but) separate issue. Can you submit a new
ticket, something along the lines of "Empty value `selected` check in
Admin Filter prevents subclassing" and we can have a look.

At first glance I can't see how both `bool(self.lookup_val_isnull)` and
`self.lookup_val_isnull == 'False'` evaluate as `True` in the `Not Empty`
case. (???) Surely the existing `empty_choice` logic would already be
broken if they did.

If you have a PR (with a test case showing the broken example) available
(or can provide one when opening the ticket) it makes it much easier to
assess.

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:11>

Django

unread,
Jan 16, 2019, 1:56:03 PM1/16/19
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* resolution: fixed => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:12>

Django

unread,
Feb 1, 2019, 3:22:51 AM2/1/19
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Sardorbek Imomaliev):

Hi Carlton,

Thanks for reply, it is not broken because there is no `Not Empty` choice
in django itself
created new issue https://code.djangoproject.com/ticket/30149

Replying to [comment:11 Carlton Gibson]:


> Hi Sardorbek.
>
> This looks like a (related but) separate issue. Can you submit a new
ticket, something along the lines of "Empty value `selected` check in
Admin Filter prevents subclassing" and we can have a look.
>
> At first glance I can't see how both `bool(self.lookup_val_isnull)` and
`self.lookup_val_isnull == 'False'` evaluate as `True` in the `Not Empty`
case. (???) Surely the existing `empty_choice` logic would already be
broken if they did.
>
> If you have a PR (with a test case showing the broken example) available
(or can provide one when opening the ticket) it makes it much easier to
assess.
>
> Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:13>

Django

unread,
Feb 7, 2019, 11:49:06 PM2/7/19
to django-...@googlegroups.com
#28687: Add a 'Not Empty' option to admin's related filter
-------------------------------------+-------------------------------------
Reporter: Brillgen Developers | Owner: Jake
Type: | Barber
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 2.0

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sardorbek Imomaliev):

* cc: Sardorbek Imomaliev (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28687#comment:14>

Reply all
Reply to author
Forward
0 new messages