Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_manager to django-cte #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions django_cte/cte.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def join(self, model_or_queryset, *filter_q, **filter_kw):
if isinstance(model_or_queryset, QuerySet):
queryset = model_or_queryset.all()
else:
queryset = model_or_queryset._default_manager.all()
queryset = self.get_manager(model_or_queryset).all()
join_type = filter_kw.pop("_join_type", INNER)
query = queryset.query

Expand All @@ -89,6 +89,16 @@ def join(self, model_or_queryset, *filter_q, **filter_kw):
query.join(QJoin(parent, self.name, self.name, on_clause, join_type))
return queryset

def get_manager(self, model):
"""Get a manager for this model

The model's default_manager will be used by default.
This method may be over-riden to use custom managers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This method may be over-riden to use custom managers
This method may be overwritten to use custom managers


:returns: A manager.
"""
return model._default_manager

def queryset(self):
"""Get a queryset selecting from this CTE

Expand All @@ -100,7 +110,7 @@ def queryset(self):
:returns: A queryset.
"""
cte_query = self.query
qs = cte_query.model._default_manager.get_queryset()
qs = self.get_manager(cte_query.model).get_queryset()

query = CTEQuery(cte_query.model)
query.join(BaseTable(self.name, None))
Expand Down