commit f7d7a97c82ee53d4ae35de50720d70f2b905a23c Author: Robbe Van Herck Date: Thu Jul 12 19:45:52 2018 +0200 Added basic db diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..894a44c --- /dev/null +++ b/.gitignore @@ -0,0 +1,104 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/app.py b/app.py new file mode 100644 index 0000000..acbbeb9 --- /dev/null +++ b/app.py @@ -0,0 +1,7 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) diff --git a/endorsement.py b/endorsement.py new file mode 100644 index 0000000..2555599 --- /dev/null +++ b/endorsement.py @@ -0,0 +1,4 @@ +from app import app, db +from models import User + +print(User.query.all()) \ No newline at end of file diff --git a/models.py b/models.py new file mode 100644 index 0000000..ec6ac76 --- /dev/null +++ b/models.py @@ -0,0 +1,20 @@ +from app import db + +class User(db.Model): + __tablename__ = "Users" + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(80), unique=True, nullable=False) + achievements = db.relationship("Achievement", backref="person", lazy=True) + endorses = db.relationship("Achievement", backref="endorsed_by", lazy=True) + + def __repr__(self): + return '' % self.username + +class Achievement(db.Model): + __tablename__ = "Achievement" + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(128), nullable=False) + person_id = db.Column(db.Integer, db.ForeignKey("Users.id")) + + def __repr__(self): + return '' % (self.name, self.person.username)