versae/qbe — pull request #22 by bocribbz (2013-05-23 11:15:10+00:00)
Title: Custom Operators

We are using QBE as reports app, but we were missing the functionality to create reports for data that happened X days ago or that will happen X days from now (editing the criteria values each time was not an option).

We have defined a CustomOperator class that can be used to create custom operations that can be added to Criteria field.

The CustomOperator class uses a metaclass to keep track of registered operators, the only condition is that it has to be written/imported in one of the files that gets evaluated at runtime (eg. models.py, urls.py, settings.py).

Each CustomOperator needs 2 attributes: slug and label.
They are used for keeping track and to append it to the Criteria field choices.

The values for CustomOperator's params and wheres must be returned by get_params and get_wheres. These 2 functions must return an iterable instance that will be appended to the query's params and wheres.

The README is updated with a sample SinceDaysAgo custom operator.

Use this at your own risk and only if you know what you are doing.