def test_several_degree_related_object(self): m1 = MiscModel(integer=1) m2 = MiscModel(integer=2) m3 = MiscModel(integer=3) m1.save() m2.save() m3.save() m1.foreign = m2 m2.foreign = m3 m3.foreign = m1 m1.save() m2.save() m3.save() q = Q(miscmodel__integer=2) self.assertEqual(1, MiscModel.objects.filter(q).count()) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q) q = Q(foreign__integer=2) self.assertEqual(1, MiscModel.objects.filter(q).count()) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q) q = Q(miscmodel__miscmodel__miscmodel__foreign__foreign__integer=2) self.assertEqual(1, MiscModel.objects.filter(q).count()) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q) q = Q(miscmodel__miscmodel__miscmodel__foreign__integer=9) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q)
def test_everything_together(self): m1 = MiscModel(text='hello', integer=5) m1.save() m2 = MiscModel(text='goodbye', integer=50) m2.save() m3 = MiscModel(text='howdy', datetime=timezone.now()) m3.save() m1.foreign = m2 m2.foreign = m3 m3.foreign = m1 m1.save() m2.save() m3.save() q = Q(text='hola') | ( Q(integer__gt=49) & Q(text='goodbye') & Q(integer__lt=500) ) | Q( miscmodel__miscmodel__miscmodel__miscmodel__foreign__foreign__integer =5) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q)
def test_everything_together(self): m1 = MiscModel(text="hello", integer=5) m1.save() m2 = MiscModel(text="goodbye", integer=50) m2.save() m3 = MiscModel(text="howdy", datetime=timezone.now()) m3.save() m1.foreign = m2 m2.foreign = m3 m3.foreign = m1 m1.save() m2.save() m3.save() q = ( Q(text="hola") | (Q(integer__gt=49) & Q(text="goodbye") & Q(integer__lt=500)) | Q(miscmodel__miscmodel__miscmodel__miscmodel__foreign__foreign__integer=5) ) self.assert_q_executes_the_same_in_python_and_sql(MiscModel, q)