﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30149	Empty value selected check in Admin Filter prevents subclassing	Sardorbek Imomaliev	VIZZARD-X	"as per https://code.djangoproject.com/ticket/28687?cnum_edit=10#comment:11 creating new issue, will get to writing test and PR next week

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`

This is easy to fix, and I would like to provide PR if this change is OK"	Cleanup/optimization	assigned	contrib.admin	dev	Normal		admin	Ülgen Sarıkavak	Accepted	1	0	0	0	0	0
