Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#9177 closed (duplicate)

list_filter cannot filter nullable fields

Reported by: bthomas Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have a model with a FloatField that is nullable. I would like to filter models that have that field set to null, so I added it to list_filter in my ModelAdmin class. When I select the "None" option, I get an exception from get_db_prep_value because it's calling float(None). I tried modifying get_db_prep_value for FloatField to return None if value is None or "None", which got rid of the exception, but did not return any results.

Will attach a patch if I figure out how to fix this to return correct results.

ForeignKey fields that are nullable do not even display a None option in the filter, but I get a similar error trying to modify the query string to use None instead of an id.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by mattmcc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Dup of #8528

comment:2 Changed 6 years ago by bthomas

My main complaint here was that there is a "None" option displayed which raises an exception when clicked, so it's not really the same as #8528, which is asking for the addition of a none/null option. I attached a patch to that ticket that fixes this, though.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.