import csv function, minor db change
This commit is contained in:
parent
b98fd07a35
commit
ae81458f7a
|
@ -1,5 +1,7 @@
|
||||||
path = "/home/sanj/c/ifa/tmp/FILMS.txt"
|
path = "/home/sanj/c/ifa/tmp/FILMS.txt"
|
||||||
|
csv_path = "/home/sanj/c/ifa/tmp/Films.sorted.csv"
|
||||||
from models import *
|
from models import *
|
||||||
|
import csv
|
||||||
|
|
||||||
def do(path=path):
|
def do(path=path):
|
||||||
errors = open("errors.txt", "w")
|
errors = open("errors.txt", "w")
|
||||||
|
@ -26,3 +28,17 @@ def do(path=path):
|
||||||
errors.write(txt)
|
errors.write(txt)
|
||||||
print title
|
print title
|
||||||
errors.close()
|
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']
|
||||||
|
|
|
@ -2,7 +2,8 @@ from django.db import models
|
||||||
|
|
||||||
class Film(models.Model):
|
class Film(models.Model):
|
||||||
title = models.CharField(max_length=512)
|
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)
|
language = models.CharField(max_length=64, blank=True)
|
||||||
year = models.IntegerField(max_length=4, blank=True, null=True)
|
year = models.IntegerField(max_length=4, blank=True, null=True)
|
||||||
available = models.BooleanField(default=False)
|
available = models.BooleanField(default=False)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user