Ejemplo n.º 1
0
def insertToDb1(data_file):
    try:
        for val in range(0, int(data_file[4])):
            authorname = data_file[1]
            authorname = authorname.split(",")
            if len(authorname) > 1:
                author, created1 = Author.objects.get_or_create(
                    name=authorname[1], surname=authorname[0])
            else:
                author, created1 = Author.objects.get_or_create(
                    name=authorname[0], surname='')
            publisher, created2 = Publisher.objects.get_or_create(
                name=data_file[3])
            Book(
                title=data_file[0],
                ISBN=1111111111111,
                page_amount=250,
                author=author,
                lend_period=LendPeriods.objects.get(id=1),
                publisher=publisher,
                status='available',
                genre=data_file[2],
            ).save()

    except Exception, e:
        print "Exception happen: " + str(
            e) + "book having problem" + data_file[0]