Created
April 10, 2019 16:32
-
-
Save 0xregulus/615da82ec824c185cb7cbc38a40a861e to your computer and use it in GitHub Desktop.
Left Join Django 1.9
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
from django.db.models.sql.datastructures import Join | |
from django.db.models.fields.related import ForeignObject | |
from django.db.models.options import Options | |
from myapp.models import Ace | |
from myapp.models import Subject | |
jf = ForeignObject( | |
to=Subject, | |
on_delete=lambda: x, | |
from_fields=[None], | |
to_fields=[None], | |
rel=None, | |
related_name=None | |
) | |
jf.opts = Options(Ace._meta) | |
jf.opts.model = Ace | |
jf.get_joining_columns = lambda: (("subj", "name"),) | |
j=Join( | |
Subject._meta.db_table, Ace._meta.db_table, | |
'T1', "LEFT JOIN", jf, True) | |
q=Ace.objects.filter(version=296) | |
q.query.join(j) | |
print q.query |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment