Задать вопрос

Тел: +7 965 3737 888

535

Просмотров

3

Ответов

Left Outer join Q object

<p>QLeftOuterJoin object allows you to create 'LEFT OUTER JOIN' sql query. It is very usefull if you have to define ForeignKey to 'null=True' (select_related will not work with null=True).
</p>
<p>You are allowed to use QLeftOuterJoin like Q object.
</p>
<p>Example:
   QLeftOuterJoin('thread_last_post', Post, 'pk', Thread, 'last_post')
</p>
<p>It will generates SQL like:
</p>
<p>LEFT OUTER JOIN appname_post AS thread_last_post ON thread_last_post.id = appname_thread.last_post_id
</p>
<p>Table could be model or string.
</p>

Вопрос полезен? Да0/Нет0
file_5175.py(2.5Кб)
None

Ответы (3):

Ответebertti:10.09.2010
Ответ полезен? Да0/Нет0

i get this error in django 1.2.1

Class1.objects.filter(QLeftOuterJoin('ord', Class1, 'id', Class2, 'class1'))

Traceback (most recent call last): File "[HTML_REMOVED]", line 1, in [HTML_REMOVED] File "C:\Python26\lib\site-packages\django\db\models\query_utils.py", line 167, in and return self._combine(other, self.AND) File "C:\Python26\lib\site-packages\django\db\models\query_utils.py", line 160, in _combine obj.add(other, conn) File "C:\Python26\lib\site-packages\django\utils\tree.py", line 95, in add if isinstance(node, Node) and (node.connector == conn_type or AttributeError: 'QLeftOuterJoin' object has no attribute 'connector'

Ответprajwala:08.12.2008
Ответ полезен? Да0/Нет0

Is this works in django 1.0

Ответkarsu:13.06.2007
Ответ полезен? Да0/Нет0

You have to put extra() method end of your query.

Example ..select_related().extra(select={ 'some_name1':'join_table_alias.column1', 'some_name2':'join_table_alias.column2', })