The Q implementation provided by this library contains a simple addition to that of Django.

Creating a Q object works as usual:

>>> from django_flexquery import Q
>>> q = Q(size__lt=10)
>>> q
<Q: (AND: ('size__lt', 10))>

But this implementation adds a prefix() method, which allows prefixing some related field’s name to the lookup keys of an existing Q object. Since Q objects can be nested, this is done recursively.

An example:

>>> q.prefix("fruits")
<Q: (AND: ('fruits__size__lt', 10))>

Nothing more to it. The real power comes when using these Q objects with FlexQuery.


Extended Q implementation with support for prefixing lookup keys.

class django_flexquery.q.Q(*args, _connector=None, _negated=False, **kwargs)

A custom Q implementation that allows prefixing existing Q objects with some related field name dynamically.


Recursively copies the Q object, prefixing all lookup keys.

The prefix and the existing filter key are delimited by the lookup separator __. Use this feature to delegate existing query constraints to a related field.


prefix (str) – Name of the related field to prepend to existing lookup keys. This isn’t restricted to a single relation level, something like “tree__fruit” is perfectly valid as well.

Returns Q