Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
data base models
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo After using models.Model on my class Im getting 'ImproperlyConfigured' error Django khavro 1 2,173 Apr-05-2021, 03:11 PM
Last Post: SheeppOSU
  Django - Am I in the right direction for creating the models of my Phone Review appli shawnmichaels583583 0 1,825 Oct-15-2019, 06:25 AM
Last Post: shawnmichaels583583
  Posting html values to views/models in Django Malt 1 2,156 Sep-04-2019, 01:44 PM
Last Post: fishhook
  Creating few models with one submit depending on the selected items from multiselect? dmytruk 0 1,874 Mar-18-2019, 03:27 AM
Last Post: dmytruk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020