-
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
isnull
for ForeignObjectRel
fields
#882
Comments
Try this:
Does this get converted to |
@carltongibson I don't believe it does. Both of these queries return no results for me (they should):
Though, I don't think I'd be able to do the opposite query ( |
After a bit more investigation, it looks like It appears that the code intends to "filter out the null value", but I don't think it's succeeding in my case. I added the following print statements to class ModelMultipleChoiceField(ChoiceIteratorMixin, forms.ModelMultipleChoiceField):
iterator = ModelChoiceIterator
def _check_values(self, value):
print 'self.null_label', self.null_label
print 'self.null_value', self.null_value
print 'self.null_label is not None: ', self.null_label is not None
print 'value: ', value
print 'self.null_value in value: ', self.null_value in value
null = self.null_label is not None and value and self.null_value in value
if null: # remove the null value and any potential duplicates
print 'We never get here because self.null_label is None'
value = [v for v in value if v != self.null_value]
result = list(super(ModelMultipleChoiceField, self)._check_values(value))
print 'We never get here because the superclass raises a ValidationError on `[u'null']`.'
result += [self.null_value] if null else []
return result This is the output for
And this is the output for
EDIT: This does filter properly if I change the null check to: |
This works if Though there are at least 2 outstanding issues with this approach:
@carltongibson if you're interested, I'd be happy to whip up a real PR for:
and/or
|
Hi @jacktrades. #915 should address this issue by enabling non-exact (eg, class Task(viewsets.ModelViewSet):
queryset = models.Task.objects.all()
filter_fields = {
'domaintask': ['exact', 'isnull'],
} The PR basically folds |
First some setup. I have the following models defined:
To get all
Task
s not referenced by aDomainTask
, Django allows:Task.objects.filter(domaintask__isnull=True)
.Using the
'django_filters.rest_framework.DjangoFilterBackend'
as a default filter, I have the following view:The following request doesn't seem to apply the
isnull
filter.I looked into the filter generation and it seems as though
BaseFilterSet.get_filters
doesn't create filters for the lookup expressions.I hacked together a proof-of-concept for supporting
isnull
here. I'm curious if there's a reasonisnull
isn't supported, or if there is an existing way to achieve this that I'm simply overlooking?The text was updated successfully, but these errors were encountered: