flask models

Solutions on MaxInterview for flask models by the best coders in the world

showing results for - "flask models"
Gabriel
19 Sep 2019
1# JOKER coding scripts
2import os
3from flask import Flask
4from flask_appbuilder import SQLA, AppBuilder
5
6# init Flask
7app = Flask(__name__)
8
9# Basic config with security for forms and session cookie
10basedir = os.path.abspath(os.path.dirname(__file__))
11app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'app.db')
12app.config['CSRF_ENABLED'] = True
13app.config['SECRET_KEY'] = 'thisismyscretkey'
14
15class Person(db.Model):
16    id = db.Column(db.Integer, primary_key=True)
17    name = db.Column(db.String(50), nullable=False)
18    addresses = db.relationship('Address', backref='person', lazy=True)
19
20class Address(db.Model):
21    id = db.Column(db.Integer, primary_key=True)
22    email = db.Column(db.String(120), nullable=False)
23    person_id = db.Column(db.Integer, db.ForeignKey('person.id'),
24        nullable=False)
25
26
27# Init SQLAlchemy
28db = SQLA(app)
29# Init F.A.B.
30appbuilder = AppBuilder(app, db.session)
31
32# Run the development server
33app.run(host='0.0.0.0', port=8080, debug=True)
Ben
13 Aug 2020
1# JOKER coding scripts
2import os
3from flask import Flask
4from flask_appbuilder import SQLA, AppBuilder
5
6# init Flask
7app = Flask(__name__)
8
9# Basic config with security for forms and session cookie
10basedir = os.path.abspath(os.path.dirname(__file__))
11app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'app.db')
12app.config['CSRF_ENABLED'] = True
13app.config['SECRET_KEY'] = 'thisismyscretkey'
14
15class Person(db.Model):
16    id = db.Column(db.Integer, primary_key=True)
17    name = db.Column(db.String(50), nullable=False)
18    addresses = db.relationship('Address', backref='person', lazy=True)
19
20class Address(db.Model):
21    id = db.Column(db.Integer, primary_key=True)
22    email = db.Column(db.String(120), nullable=False)
23    person_id = db.Column(db.Integer, db.ForeignKey('person.id'),
24        nullable=False)
25
26
27# Init SQLAlchemy
28db = SQLA(app)
29# Init F.A.B.
30appbuilder = AppBuilder(app, db.session)
31
32# Run the development server
33app.run(host='0.0.0.0', port=8080, debug=True)
Elona
11 Jan 2017
1# JOKER coding scripts
2import os
3from flask import Flask
4from flask_appbuilder import SQLA, AppBuilder
5
6# init Flask
7app = Flask(__name__)
8
9# Basic config with security for forms and session cookie
10basedir = os.path.abspath(os.path.dirname(__file__))
11app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'app.db')
12app.config['CSRF_ENABLED'] = True
13app.config['SECRET_KEY'] = 'thisismyscretkey'
14
15class Person(db.Model):
16    id = db.Column(db.Integer, primary_key=True)
17    name = db.Column(db.String(50), nullable=False)
18    addresses = db.relationship('Address', backref='person', lazy=True)
19
20class Address(db.Model):
21    id = db.Column(db.Integer, primary_key=True)
22    email = db.Column(db.String(120), nullable=False)
23    person_id = db.Column(db.Integer, db.ForeignKey('person.id'),
24        nullable=False)
25
26
27# Init SQLAlchemy
28db = SQLA(app)
29# Init F.A.B.
30appbuilder = AppBuilder(app, db.session)
31
32# Run the development server
33app.run(host='0.0.0.0', port=8080, debug=True)
similar questions
queries leading to this page
flask models