-
Notifications
You must be signed in to change notification settings - Fork 178
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
IS NULL
with REST API
#122
Comments
+1 for a fix. Since the api doesn't support negation, I'm guess that 'is' implies 'is null'. I needed this to work, so I hacked it in by overriding RestResource.process_query and treating the 'is' operator differently. Any thoughts around a better implementation? def process_query(self, query):
...
# clean and normalize the request parameters
for key in request.args:
if '__' in key:
expr, op = key.rsplit('__', 1)
if op not in DJANGO_MAP:
expr = key
op = 'eq'
else:
expr = key
op = 'eq'
# OP_IS implies that the value is None
if op == 'is':
raw_filters[expr] = [(op, [None])]
else:
raw_filters.setdefault(expr, [])
raw_filters[expr].append((op, request.args.getlist(key)))
...
return query |
The API supports negation, at least in the current version. But that does not change much here. The setting of the value to None and thus the override of process_query would probably not be necessary if db_value of a ForeignKey would return None for empty strings. Is that an option? |
model.filter(field__null=False)
|
Does anybody plan to fix it officially? It would be great to get rid of this ridiculous limitation. # flask_peewee/rest.py
if '__' in key:
expr, op = key.rsplit('__', 1)
if op not in DJANGO_MAP:
expr = key
if op == 'isnull':
op = 'is'
# transform value and 'negated' flag here if needed
else:
op = 'eq'
.... |
Looks to not be working.
The text was updated successfully, but these errors were encountered: