How To Make An Inner Join In Django Without Foreign Key?
how to make statement of join on in django 1.11, i want to create this statement :
select t1.name ,t2.str, t2.num from table_1 as t1 join table_2 as t2 on t2.product_id = t1.id and t2.section_num = 2; the models: class t1(UTModelTS): alt_keys = product_alt_keys name = utCharField() ... class t2(UTModelTS): alt_keys= [('pr_id', 'section')] str = utCharField() num = models.IntegerField() ...
t1 = t1.objects.filter(**params).exclude(**exclude) t1 = t1.select_related('t2') `
but this make no sense since acoridng to django doc : select_related Returns a QuerySet that will “follow” foreign-key relationships... from https://docs.djangoproject.com/en/2.2/ref/models/querysets/ .
No, there isn't an effective / elegant way unfortunately.
although you can use
.raw()/RawSQL() method for this exact thing. Even if it could it probably would be a lot slower than raw SQL.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module