在Django中创建对象的更好方法

时间:2012-08-26 17:03:09

标签: python django object csv

我正在寻找一些更“美丽”的东西来完成我在这里做的事情。 现在很好用。

f = open(pathdata+'blocoh2.csv', 'r')
reader = csv.reader(f)
for row in reader:
    dpt, created = Departamento.objects.get_or_create(name = row[3])
    print str(created) + "dprmentp"
    blc, created = Bloco.objects.get_or_create(nm_andar = row[5],name = row[6])
    print str(created) + "bloco"
    tplugar, created = TipoLugar.objects.get_or_create(name = (smart_str(row[2])))
    print str(created) + "tipo_lugar"
    lugar, created = Lugar.objects.get_or_create(name=row[0], utilizacao=row[1], 
                  tipoLugar = tplugar,
                  metragem = 0,
                  coordx = 0,
                  coordy = 0,
                  bloco = blc,
                  departamento = dpt)
    print str(created) + "lugar"

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以阅读PEP8并将代码格式化为此Python标准。