Added new functionality, refactored, added CHANGELOG.md, and more
This commit is contained in:
50
accounts/models/visit/__init__.py
Normal file
50
accounts/models/visit/__init__.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from datetime import datetime
|
||||
|
||||
# Import SQLAlchemy enum type
|
||||
from sqlalchemy import Enum
|
||||
|
||||
# Import db
|
||||
from accounts.models import db
|
||||
|
||||
# Import custom enum db column
|
||||
from accounts.models.status import Status
|
||||
from accounts.models.visit.visit_type import VisitType
|
||||
|
||||
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')
|
||||
visit_type = db.Column(Enum(VisitType), default=VisitType.MEDIUM_MINUTE_WALK)
|
||||
dog_id = db.Column(db.Integer, db.ForeignKey('dogs.id'), nullable=False)
|
||||
dogs = db.relationship('Dog', back_populates='visits')
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
|
||||
|
||||
def get_date(self):
|
||||
year = self.date_time.year
|
||||
month = self.date_time.month
|
||||
day = self.date_time.month
|
||||
|
||||
return f'{year}-{month}-{day}'
|
||||
|
||||
def get_time(self):
|
||||
hour = self.date_time.hour
|
||||
minute = self.date_time.minute
|
||||
|
||||
if hour == 0 and minute == 0:
|
||||
return 0
|
||||
|
||||
else:
|
||||
return f'{hour}:{minute}'
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'ID': self.id,
|
||||
'Date-Time': self.date_time,
|
||||
'Owner-ID': self.owner_id,
|
||||
'Dog-ID': self.dog_id
|
||||
}
|
||||
|
||||
9
accounts/models/visit/visit_type.py
Normal file
9
accounts/models/visit/visit_type.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from enum import Enum
|
||||
from enum import auto
|
||||
|
||||
class VisitType(Enum):
|
||||
SMALL_MINUTE_WALK = auto()
|
||||
MEDIUM_MINUTE_WALK = auto()
|
||||
LARGE_MINUTE_WALK = auto()
|
||||
HOUSE_SITTING = auto()
|
||||
|
||||
Reference in New Issue
Block a user