Login

QEmpty

Author:
dottedmag
Posted:
June 10, 2007
Language:
Python
Version:
.96
Tags:
q query
Score:
2 (after 2 ratings)

Q() value in Django is identity for & operation: Q() & foo & bar & ... == foo & bar & ...

QEmpty() is complimentary identity for | operation: QEmpty() | foo | bar | ... == foo | bar | ...

QEmpty() itself returns empty queryset.

Handy for complex query generation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class QEmpty(object):
    def __init__(self):
        pass

    def __and__(self, other):
        return QAnd(self, other)

    def __or__(self, other):
        return QOr(self, other)

    def get_sql(self, opts):
        return {}, ['42=0'], []

More like this

  1. QLeftOuterJoins by dottedmag 7 years, 8 months ago
  2. CustomQueryManager by zvoase 6 years, 7 months ago
  3. Humanize lists of strings in templates by ChipX86 7 years, 8 months ago
  4. Query lookups using operators by diverman 4 years, 7 months ago
  5. {% ifthis FOO isoneof BAR BAZ ... %} by sjl 4 years, 9 months ago

Comments

Please login first before commenting.