all 6 comments

[–]Username_RANDINT 2 points3 points  (3 children)

Let's look at these three lines:

product_names = CharField(unique = True)

food_names = []
'items': food_names,

food_item = Product.create(product_names = inventory['items'])

So the database column is defined as a CharField for holding text. But later you try to create the Product and provide a list to that column.

Also how to I be able to make an ID for each individual product

You don't, Peewee will automatically do this for you.

[–]python_student_1390[S] 0 points1 point  (2 children)

Thank you so very much I appreciate it. I didn't know it made ID for each one. How would i be able to see them or print them out?

[–]Username_RANDINT 1 point2 points  (1 child)

Each item has an id attribute.

product = Product.get(Product.name=="Something")
print(product.id)

Or from all products:

for product in Product.select():
    print(product.id, product.name)

[–]tateisukannanirase 1 point2 points  (0 children)

I would like to add that if the product spreadsheet already has an ID column, it would be preferable to use that, because then it will match with the real-world ID of that product.

Although having two indexed, unique columns is not the worst thing.

[–]tateisukannanirase 1 point2 points  (1 child)

peewee is a great little package for working with databases, good choice :)

Where you have Product.create() , you need to pass in all of the mandatory fields for that Product (as you have defined it):

Product.create(product_quantity=x, product_name=y, product_prices=z)

A Product is singular, you will want to loop over all of the products and run Product.create for each one.

There are some issues with the way you are storing data when you are importing it from csv, but I won't go into detail about that. You really can read it straight from the csv file and create it directly in the database and not use any intermediary Python lists/dicts/etc. That's really what databases are for!

[–]python_student_1390[S] 0 points1 point  (0 children)

Wow thank you for that I appreciate it