Skip to content
Snippets Groups Projects

Resolve "creating database flask-sqlalchemy"

Merged Herman Andersen Dyrkorn requested to merge 3-creating-database-flask-sqlalchemy into master
1 file
+ 33
1
Compare changes
  • Side-by-side
  • Inline
+ 33
1
from flask import Flask, request
from flask_restful import Api, Resource
import os.path
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)
api = Api(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(255), nullable=False)
email = db.Column(db.String(255), nullable=False)
pwd = db.Column(db.String(255), nullable=False)
class Salamander(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
sex = db.Column(db.String(255), nullable=False)
species = db.Column(db.String(255), nullable=False)
location = db.Column(db.String(255), nullable=False)
location_id = db.Column(db.Integer, db.ForeignKey('location.id'), nullable=False)
image_path = db.Column(db.String(255), nullable=False)
uid = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
date = db.Column(db.DateTime, default=datetime.now)
class Location(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(255), nullable=False)
coordinates = db.Column(db.String(255), nullable=False)
pwd = db.Column(db.String(255), nullable=False)
radius = db.Column(db.Integer, nullable=False)
# matchSalamander endpoint
class MatchSalamander(Resource):
@staticmethod
def post():
@@ -40,6 +72,7 @@ class MatchSalamander(Resource):
return output
# findSalamanderInfo endpoint
class FindSalamanderInfo(Resource):
@staticmethod
def post():
@@ -63,7 +96,6 @@ def get_path(data, end_directory):
def directory_not_empty(directory_path):
if os.path.exists(directory_path) and not os.path.isfile(directory_path):
# Checking if the directory is empty or not
if not os.listdir(directory_path):
return False
Loading