print("Reading CART_CONTENT model ...")

        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]
Example #2
0
django.setup()

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()