import csv function, minor db change

This commit is contained in:
Sanj 2012-11-15 14:05:18 +05:30
parent b98fd07a35
commit ae81458f7a
2 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,7 @@
path = "/home/sanj/c/ifa/tmp/FILMS.txt"
csv_path = "/home/sanj/c/ifa/tmp/Films.sorted.csv"
from models import *
import csv
def do(path=path):
errors = open("errors.txt", "w")
@ -26,3 +28,17 @@ def do(path=path):
errors.write(txt)
print title
errors.close()
def import_csv(path=csv_path):
lines = csv.reader(open(path))
for line in lines:
d = {
'title': line[0],
'year': int(line[1].replace('"', '')[0:4]),
'director': line[2],
'producer': line[3],
'language': line[4]
}
f = Film(**d)
f.save()
print d['title']

View File

@ -2,7 +2,8 @@ from django.db import models
class Film(models.Model):
title = models.CharField(max_length=512)
director = models.CharField(max_length=512)
director = models.CharField(max_length=512, blank=True)
producer = models.CharField(max_length=512, blank=True)
language = models.CharField(max_length=64, blank=True)
year = models.IntegerField(max_length=4, blank=True, null=True)
available = models.BooleanField(default=False)