from BookDetails.models import BOOK, AUTHOR, PUBLISHER_INFO, GENRE

count = 0
data = csv.reader(open(
    "/home/HOMEGROUP/adelg000/school/CEN4010/BookStore/sample_data/BOOK.csv"),
                  delimiter=",")

for row in data:

    if count == 1:
        print("Reading BOOK model ...")

        book = BOOK()

        book.ISBN = row[0]
        print("ISBN = " + book.ISBN)

        # Reading Genre ...
        gList = GENRE.objects.filter(GenreID=row[1])
        if gList:
            g = gList[0]

            if g:
                book.GenreID = g
        else:
            g = GENRE()
            g.GenreID = row[1]
            g.save()
            book.GenreID = g
        print("GenreID = " + book.GenreID.GenreID)
        cc = CART_CONTENT()

        cc.Cart_contentID = int(row[0])
        print("Cart_contentID = " + str(cc.Cart_contentID))

        # Reading ISBN ...
        bList = BOOK.objects.filter(ISBN=row[1])
        if bList:
            b = bList[0]

            if b:
                cc.ISBN = b
        else:
            b = BOOK()
            b.ISBN = row[1]
            b.save()
            cc.ISBN = b
        print("ISBN = " + cc.ISBN.ISBN)

        # Reading Cart_ID ...
        cList = CART.objects.filter(Cart_ID=row[2])
        if cList:
            c = cList[0]

            if c:
                cc.Cart_ID = c
        else:
            c = CART()
            c.Cart_ID = row[2]
            c.save()
			u = uList[0]

			if u:
				content.Username = u;
		else:
			u = USER()
			u.Username = row[1]
			u.save()
			content.Username = u
		print("Username= "******"ISBN = " + content.ISBN.ISBN)

		content.save()
		print("SAVED_FOR_LATER_CONTENT read SUCCESSFUL")

	count = 1