Ejemplo n.º 1
0
 def setUp(self):
     target = ForeignKeyTarget(name='target-1')
     target.save()
     new_target = ForeignKeyTarget(name='target-2')
     new_target.save()
     for idx in range(1, 4):
         source = ForeignKeySource(name='source-%d' % idx, target=target)
         source.save()
 def setUp(self):
     target = ForeignKeyTarget(name="target-1")
     target.save()
     new_target = ForeignKeyTarget(name="target-2")
     new_target.save()
     for idx in range(1, 4):
         source = ForeignKeySource(name="source-%d" % idx, target=target)
         source.save()
    def test_foreign_key_with_unsaved(self):
        source = ForeignKeySource(name='source-unsaved')
        expected = {'id': None, 'name': 'source-unsaved', 'target': None}

        serializer = ForeignKeySourceSerializer(source)

        # no query if source hasn't been created yet
        with self.assertNumQueries(0):
            self.assertEqual(serializer.data, expected)
Ejemplo n.º 4
0
    def setUp(self):
        """
        Create 3 BasicModel instances.
        """
        items = ['foo', 'bar', 'baz']
        for item in items:
            t = ForeignKeyTarget(name=item)
            t.save()
            ForeignKeySource(name='source_' + item, target=t).save()

        self.objects = ForeignKeySource.objects
        self.data = [{
            'id': obj.id,
            'name': obj.name
        } for obj in self.objects.all()]
        self.view = FKInstanceView.as_view()