def run(): print "hello" contents = csv.reader(open("%s/../data/gallery.csv" % os.path.dirname(__file__)), dialect='excel', delimiter=',', quotechar='"') header = contents.next() for row in contents: aw = Artwork() aw.level = row[0].strip() aw.work_num = row[1].strip() aw.artist = ' '.join((row[2].strip(), row[3].strip())) aw.title = row[4].strip() aw.year = row[5].strip() aw.medium = row[6].strip() aw.credit = row[7].strip() aw.website = row[8].strip() aw.save()
def migrate_artworks(): """ IDFM, Titulo, Creation_year_start, Creation_year_end, inscription, notes, Original_place: (Nombre lugar + Pais + Provincia + Poblacion), Current_place: (Nombre lugar + Pais + Provincia + Poblacion), size, serie, NºInventario, Descriptores """ print "Migrando Artworks" admin_user = User.objects.get(id=1) Artwork.objects.all().delete() reader = csv.reader(open('migrations/FMArtworks.csv'), delimiter=',', quotechar='"') for row in reader: artwork = Artwork() artwork.id = row[0] artwork.title = row[1] try: creation_year_start = int(row[2]) artwork.creation_year_start = creation_year_start except ValueError: pass try: creation_year_end = int(row[3]) artwork.creation_year_end = creation_year_end except ValueError: pass artwork.inscription = row[4] artwork.notes = row[5] artwork.size = row[14] try: fm_serie = int(row[15]) try: serie = Serie.objects.get(id=fm_serie) artwork.serie = serie except Serie.DoesNotExist: pass except ValueError: pass artwork.inventory = row[16] artwork.user = admin_user artwork.fm_original_place = "%s, %s, %s, %s" % (row[6], row[7], row[8], row[9]) artwork.fm_current_place = "%s, %s, %s, %s" % (row[10], row[11], row[12], row[13]) artwork.fm_inventory = row[16] artwork.fm_descriptors = row[17] artwork.save()