Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mixins beat subclassing

  • Loading branch information...
commit 916e8ef731573b2d94a1db10e437d12a5c7e8caf 1 parent 94bd93b
@mitsuhiko authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 sqlalchemy_django_query.py
View
12 sqlalchemy_django_query.py
@@ -24,9 +24,9 @@
from sqlalchemy.sql import operators, extract
-class DjangoQuery(Query):
- """A subclass of a regular SQLAlchemy query object that implements
- more Django like behavior:
+class DjangoQueryMixin(object):
+ """Can be mixed into any Query class of SQLAlchemy and extends it to
+ implements more Django like behavior:
- `filter_by` supports implicit joining and subitem accessing with
double underscores.
@@ -87,7 +87,7 @@ def order_by(self, *args):
column = column.desc()
args[idx] = column
- q = Query.order_by(self, *args)
+ q = super(DjangoQueryMixin, self).order_by(*args)
for join in joins_needed:
q = q.join(join)
return q
@@ -115,3 +115,7 @@ def _filter_or_exclude(self, negate, kwargs):
column = None
q = q.reset_joinpoint()
return q
+
+
+class DjangoQuery(DjangoQueryMixin, Query):
+ pass
Please sign in to comment.
Something went wrong with that request. Please try again.