Last active
October 11, 2017 18:52
-
-
Save pavelpatrin/0e4c9a4d038fb999f24055374fb0fe1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RawJoin(Join): | |
u"""Позволяет внедрить в QuerySet произвольный JOIN. | |
banners_qs = Banner.objects.extra(where=['my_join_table.status = 123']) | |
Join('LEFT JOIN (XXX) b1 ON b1.id = abcd ', ()).inject(banners_qs) | |
""" | |
def __init__(self, raw_sql, params): | |
# Используемые опции. | |
self.raw_sql = raw_sql | |
self.params = params | |
# Соответствие интерфейса. | |
self.table_alias = 'raw_join' | |
self.table_name = None | |
self.parent_alias = None | |
self.join_field = None | |
self.join_cols = None | |
self.join_type = None | |
self.nullable = None | |
def as_sql(self, compiler, connection): | |
return self.raw_sql, self.params | |
def inject(self, queryset): | |
queryset.query.get_initial_alias() | |
queryset.query.table_alias(self.table_alias, True) | |
queryset.query.alias_map[self.table_alias] = self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment