Beispiel #1
0
    def test_instance_default_manager(self):
        def default_manager(instance):
            return (
                type(instance.__class__._default_manager),
                instance.__class__._default_manager.model,
            )

        plain_a = PlainA(field1="C1")
        plain_b = PlainB(field2="C1")
        plain_c = PlainC(field3="C1")

        model_2a = Model2A(field1="C1")
        model_2b = Model2B(field2="C1")
        model_2c = Model2C(field3="C1")

        self.assertEqual(default_manager(plain_a), (models.Manager, PlainA))
        self.assertEqual(default_manager(plain_b), (models.Manager, PlainB))
        self.assertEqual(default_manager(plain_c), (models.Manager, PlainC))

        self.assertEqual(default_manager(model_2a),
                         (PolymorphicManager, Model2A))
        self.assertEqual(default_manager(model_2b),
                         (PolymorphicManager, Model2B))
        self.assertEqual(default_manager(model_2c),
                         (PolymorphicManager, Model2C))
Beispiel #2
0
    def test_translate_polymorphic_q_object(self):
        self.create_model2abcd()

        q = Model2A.translate_polymorphic_Q_object(Q(instance_of=Model2C))
        objects = Model2A.objects.filter(q)
        self.assertQuerysetEqual(objects, [Model2C, Model2D],
                                 transform=lambda o: o.__class__,
                                 ordered=False)
    def test_translate_polymorphic_q_object(self):
        self.create_model2abcd()

        q = Model2A.translate_polymorphic_Q_object(Q(instance_of=Model2C))
        objects = Model2A.objects.filter(q)
        self.assertQuerysetEqual(
            objects,
            [Model2C, Model2D],
            transform=lambda o: o.__class__,
            ordered=False,
        )