如何将我的数据写入 json 文件?这是我的尝试:
from django.test import TestCase
from django_dynamic_fixture import G
import content.factories
from django.core import serializers
from content.models import UserProfile, Delivery
from django.contrib.auth.models import User
class DeliveryTest(TestCase):
def test_sample_data(self):
for i in range(0,10):
user = content.factories.UserFactory.create()
print user
for j in range(0, 50):
delivery = content.factories.DeliveryFactory.create(user=user)
print delivery
with open("file.json", "w") as out:
data = serializers.serialize("json", User.objects.all() )
with open("file.json", "w") as out:
data2 = serializers.serialize("json", Delivery.objects.all() )