Answer the question
In order to leave comments, you need to log in
How to create and populate a dict object with sqlite3 keys?
Now I have a list and a database that looks like this:
It has 3 tables category, product, media
And I create a list like this:
def select_product_all(self):
with self.connection:
products = []
for product in self.cursor.execute("SELECT * FROM products_product, products_product_media WHERE products_product.id = products_product_media.product_id").fetchall():
products.append(product)
self.connection.close()
return products
For an ordinary cactus, the image corresponds to media / 1.jpg
print ("Для", products[0][1] , " соответствует картинка" , products[0][6])
print("Для", products.name , " соответствует картинка" , products.media])
Answer the question
In order to leave comments, you need to log in
I feel that you have reached the point where you need an ORM, tk. dict is exactly what you don't need here. I think it's worth looking at SqlAlchemy as the most common one. Do not pay attention if the examples and articles are about, for example, mysql. Most likely your code will differ only in the database connection string.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question