Python Forum

Full Version: data base models
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,im pretty new at python,
but im about to start the developing of a web application, ,so i will be using flask and mysql with SQL alchemy

but the project has already a huge database, so as far as i have learned python i need to have my "models.py" file with the table structure like this
 
from flask_blog import db


class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(80))
    email = db.Column(db.String(35), unique=True)
    username = db.Column(db.String(80), unique=True)
    password = db.Column(db.String(60))
    is_author = db.Column(db.Boolean)
    new = db.Column(db.Integer)

    def __init__(self, fullname, email, username, password, is_author=False):

        self.fullname = fullname
        self.email = email
        self.username = username
        self.password = password
        self.is_author = is_author

    def __repr__(self):
        return '<Author %r>' % self.username
but it will be very painfull and inefficient to write the code for each table,
is there a tool, or a trick that i can use to autogenerate the code? i have been searching for that in the internet but didnt find anything like that
There are tools for this such as https://pypi.org/project/sqlacodegen/. You could try this. By the way, it is not at all hard to find in the internet.