def test_many_to_many_and_foreignkey(self):
    with transaction.atomic():
        self.create_foo_objects()
        self.create_bar_objects()
        BarFooFooModel.objects.create(barfoo1=BarModel.objects.get(pk=1))
    mixed_obj = MixedFooBarModel.objects.create(barfoo=BarFooFooModel.objects.get(pk=1))
    mixed_obj.foofoo.add(FooModel.objects.get(pk=1))
    mixed_obj.foofoo.add(FooModel.objects.get(pk=2))
    mixed_obj.barbar.add(BarModel.objects.get(pk=2))
    mixed_obj.barbar.add(BarModel.objects.get(pk=3))
    obj = MixedFooBarModel.objects.get(pk=1)
    obj_data = ujson.loads(obj.to_json())
    obj_expected_result = self.get_expected_result(self.result_many_to_many())
    self.assertEqual(obj_data, obj_expected_result)
def test_many_to_many_and_foreignkey(self):
    with transaction.atomic():
        self.create_foo_objects()
        self.create_bar_objects()
        BarFooFooModel.objects.create(barfoo1=BarModel.objects.get(pk=1))
    mixed_obj = MixedFooBarModel.objects.create(barfoo=BarFooFooModel.objects.get(pk=1))
    mixed_obj.foofoo.add(FooModel.objects.get(pk=1))
    mixed_obj.foofoo.add(FooModel.objects.get(pk=2))
    mixed_obj.barbar.add(BarModel.objects.get(pk=2))
    mixed_obj.barbar.add(BarModel.objects.get(pk=3))
    obj = MixedFooBarModel.objects.get(pk=1)
    obj_data = ujson.loads(obj.to_json())
    obj_expected_result = self.get_expected_result(self.result_many_to_many())
    self.assertEqual(obj_data, obj_expected_result)