Query¶
Specialized has_any and has_all query lookups for flag enumerations.
- class django_enum.query.HasAllFlagsLookup(*args, **kwargs)[source]¶
Bases:
LookupQuery whether the left-hand side has all the bit flags on the right-hand side. This lookup bitwise ANDs the left-hand side with the right-hand side and checks that the result is equal to the right-hand side.
- as_sql(compiler, connection)[source]¶
Responsible for returning a (sql, [params]) tuple to be included in the current query.
Different backends can provide their own implementation, by providing an as_{vendor} method and patching the Expression:
``` def override_as_sql(self, compiler, connection):
# custom logic return super().as_sql(compiler, connection)
setattr(Expression, ‘as_’ + connection.vendor, override_as_sql) ```
- Arguments:
compiler: the query compiler responsible for generating the query. Must have a compile method, returning a (sql, [params]) tuple. Calling compiler(value) will return a quoted value.
connection: the database connection used for the current query.
- Return: (sql, params)
Where sql is a string containing ordered sql parameters to be replaced with the elements of the list params.
- lookup_name = 'has_all'¶
- class django_enum.query.HasAnyFlagsLookup(*args, **kwargs)[source]¶
Bases:
LookupQuery whether the left-hand side has any of the bit flags on the right-hand side. This lookup bitwise ANDs the left-hand side with the right-hand side and checks that the result is not equal to zero.
- as_sql(compiler, connection)[source]¶
Responsible for returning a (sql, [params]) tuple to be included in the current query.
Different backends can provide their own implementation, by providing an as_{vendor} method and patching the Expression:
``` def override_as_sql(self, compiler, connection):
# custom logic return super().as_sql(compiler, connection)
setattr(Expression, ‘as_’ + connection.vendor, override_as_sql) ```
- Arguments:
compiler: the query compiler responsible for generating the query. Must have a compile method, returning a (sql, [params]) tuple. Calling compiler(value) will return a quoted value.
connection: the database connection used for the current query.
- Return: (sql, params)
Where sql is a string containing ordered sql parameters to be replaced with the elements of the list params.
- lookup_name = 'has_any'¶