0

这是我的模型:

class Company(models.Model):      
    id = models.AutoField(primary_key=True);
    name = models.CharField(max_length=100);
    address = models.CharField(max_length=100, null=True);
    city = models.CharField(max_length=100);
    state = models.CharField(max_length=25);
    zip = models.IntegerField();
    latitude = models.CharField(max_length=20, null=True)
    longitude = models.CharField(max_length=20, null=True)  
    phone = models.CharField(max_length=15, null=True);
    website = models.CharField(max_length=50, null=True);
    email = models.EmailField(max_length=50, null=True);
    hiring = models.BooleanField(default=False);    
    approved = models.BooleanField(default=False);
    date_added = models.DateTimeField(auto_now_add=True);
    about_us = models.TextField(max_length=500, null=True);

我有这样的数据:

    Id: since this is autofield, do i need to enter this?
    Name: 1-800 Postcards America's Printing Company
    Address: 121 Varick Street, 7th Floor
    City: New York
    State: NY
    Zip: 10013
    Latitude: 40.724831999999999
    Longitude: -74.00609
    Phone: 212-741-1070
    Website: http://www.1800postcards.com
    Email: info@1800postcards.com
    Hiring: No
    Approved: True
    Date Added: auto added as well, should I add a random date?
    About Us: Some about us with, many, commas, possible, etc.

我需要将大约 50 多家使用 django 的公司上传到 gae 数据存储。如何创建 csv 文件以确保数据正确插入?

4

1 回答 1

1

我不是 100% 确定这会起作用,但我会编写一个 python 函数来读取您的文件,逐行解析数据,然后创建并保存 Company 类。我会在 dev_appserver 上测试一下。

然后我会在远程外壳中运行该功能。它应该从本地磁盘读取文本文件,并保存到真实的数据存储中。

于 2012-05-03T19:51:30.633 回答