import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
SELECT Posts.name, Posts.msg, Users.name, Pages.name
from Posts INNER JOIN Users ON Posts.user_id = Users.id
INNER JOIN Pages ON Posts.page_id = Pages.id
WHERE user_id = 137 or page_id = 38
GROUP BY Posts.name, Posts.msg, Users.name, Pages.name
class Tab1(models.Model):
name = models.CharField(max_length=50)
class Tab2(models.Model):
something = models.CharField(max_length=50)
table1 = models.ManyToManyField('Tab1', through='Tab3')
class Tab3(models.Model):
quantity = models.IntegerField()
l1_id = models.ForeignKey('Tab1')
l2_id = models.ForeignKey('Tab2')
t3_d = Tab3.objects.filter(l1_id=1)
t3_d.values('l1_id__id', 'l2_id__id', 'l2_id__something', 'quantity')
[{'l1_id__id': 1, 'l2_id__something': u's3', 'l2_id__id': 3, 'quantity': 20}, {'l1_id__id': 1, 'l2_id__something': u's1', 'l2_id__id': 1, 'quantity': 50}]