CHANGED dev-server.py logic moved into tests/testing_app.py as create_app function, UPDATED tests to use new create_app function, UPDATED shell.nix to work with create_app and testing_app.py, ADDED DB models now defined in accounts/models, ADDED Visit DB model
This commit is contained in:
4
accounts/models/__init__.py
Normal file
4
accounts/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
21
accounts/models/dog.py
Normal file
21
accounts/models/dog.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from accounts.models import db
|
||||
|
||||
class Dog(db.Model):
|
||||
__tablename__ = 'dogs'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String, nullable=False)
|
||||
breed = db.Column(db.String, nullable=False)
|
||||
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
owner = db.relationship('User', backref='dogs')
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'breed': self.breed,
|
||||
'owner': self.owner
|
||||
}
|
||||
|
||||
34
accounts/models/user.py
Normal file
34
accounts/models/user.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# Import db
|
||||
from accounts.models import db
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
username = db.Column(db.String, unique=True, nullable=False)
|
||||
email = db.Column(db.String, nullable=False)
|
||||
address = db.Column(db.String, nullable=False)
|
||||
password = db.Column(db.String, nullable=False)
|
||||
visits = db.relationship('Visit', back_populates='owner')
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.username}'
|
||||
|
||||
# Retrieve all booked visits
|
||||
def get_bookings(self):
|
||||
return [visit for visit in self.visits]
|
||||
|
||||
# Retrieve past booked visits
|
||||
def get_bookings_history(self):
|
||||
from datetime import datetime
|
||||
current_time = datetime.now()
|
||||
|
||||
return [visit for visit in self.visits if visit.date_time < current_time]
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'username': self.username,
|
||||
'email': self.email,
|
||||
'password': self.password,
|
||||
}
|
||||
|
||||
21
accounts/models/visit.py
Normal file
21
accounts/models/visit.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Import db
|
||||
from accounts.models import db
|
||||
|
||||
class Visit(db.Model):
|
||||
__tablename__ = 'visits'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
date_time = db.Column(db.DateTime, nullable=False)
|
||||
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
owner = db.relationship('User', back_populates='visits')
|
||||
dog_id = db.Column(db.Integer, db.ForeignKey('dogs.id'), nullable=False)
|
||||
dog = db.relationship('Dog', backref='visits')
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'ID': self.id,
|
||||
'Date-Time': self.date_time,
|
||||
'Owner-ID': self.owner_id,
|
||||
'Dog-ID': self.dog_id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user