deal with erroneous year entries

This commit is contained in:
Sanj 2012-11-15 15:10:27 +05:30
parent d94ccc2812
commit 934fd54009
2 changed files with 11 additions and 2 deletions

View File

@ -31,13 +31,21 @@ def do(path=path):
def import_csv(path=csv_path):
lines = csv.reader(open(path))
try:
year = int(line[1].replace('"', '')[0:4])
year_error = False
except:
year = None
year_error = True
for line in lines:
d = {
'title': line[0],
'year': int(line[1].replace('"', '')[0:4]),
'year': year,
'director': line[2],
'producer': line[3],
'language': line[4]
'language': line[4],
'year_error': year_error
}
f = Film(**d)
f.save()

View File

@ -6,6 +6,7 @@ class Film(models.Model):
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)
year_error = models.BooleanField(default=False)
available = models.BooleanField(default=False)
notes = models.TextField(blank=True)