-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix null filtering for *Choice filters #680
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #680 +/- ##
===========================================
+ Coverage 98.11% 98.21% +0.09%
===========================================
Files 15 15
Lines 1117 1179 +62
===========================================
+ Hits 1096 1158 +62
Misses 21 21
Continue to review full report at Codecov.
|
Hi @carltongibson - finally got around to writing the test for #710. This PR should be ready for review now. |
OK. Great thanks. I'll review all, and roll a new release shorty* [*] ≈Before end of Summer |
81c38cb
to
50f7275
Compare
rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely. Lets have it! 👍
* Add test cases from PR 639. Thanks @michael-mri! * Fix tests for null choice iterator * Add more null value tests * Add null choice to various (Model)ChoiceFields * Fix django < 1.11 field iterator handling * Resolve #710 - add test for lazy callable choices
This is an update that should supersede/close #639. Thanks @michael-mri for an initial implementation and some test cases.
TODO:
In short, the null option handling is moved to a set of custom fields and out of the
ChoiceFilter
. This code largely emulates and extends what's done byforms.ModelChoiceField
already. eg, theChoiceIterator
basically copies the behavior ofModelChoiceIterator
and addsempty_label
handling toChoiceField
&MultipleChoiceField
. Null choice handling is just an extension of the empty choice.Notes:
ChoiceIteratorMixin
is probably the most confusing bit to reason about, due to howModelChoiceField
s can set bothqueryset
andchoices
.ModelChoiceField
&ModelMultipleChoiceField
both validate the incoming values as part of the queryset. This check essentially has to be bypassed fornull_value
s.ModelChoiceField
,ChoiceField
doesn't already supportempty_label
(added in the PR).MultipleChoiceField
explicitly setsempty_label
to none, since it's an option that never makes sense. This is the same behavior asforms.ModelMultipleChoiceField
.null_label
handling forManyToManyField
s inFILTER_FOR_DBFIELD_DEFAULTS
since the null option is not present/implicit.AllValuesFilter
, which should be fixed).