0

I use the following code to inserting data in DB:

db = dbConnection("localhost", "root", "")

class Products(peewee.Model):
    article = peewee.TextField()
    name = peewee.TextField()
    price = peewee.TextField()
    price_distributor = peewee.TextField()
    price_discount = peewee.TextField()

    class Meta:
        database = db

Products.create_table()
book = Products(article="1", name="2", price="3", price_distributor="4", price_discount="5")
book.save()

And connection function:

def dbConnection(host, user, password):
    return peewee.MySQLDatabase("test", host=host, port=3306, user=user, passwd=password)

How to set table name in which I insert data?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
POV
  • 11,293
  • 34
  • 107
  • 201
  • Take a look at the following post: https://stackoverflow.com/questions/25709353/dynamically-define-name-of-class-in-peewee-model -- specifically the answer from @coleifer – David Tansey Nov 15 '17 at 19:31
  • Could you please clarify your question? when you save the product - the data is saved to the Products table, that's how you specify the table. – taras Nov 15 '17 at 19:33
  • Really? will it create table if not exsist? – POV Nov 15 '17 at 19:47

1 Answers1

1

If you take a look at the docs on peewee model options

There is an option you can specify in class Meta called db_table which is the name of the table to store data.

tread
  • 10,133
  • 17
  • 95
  • 170