class Event(db.Model): """ event table """ __tablename__ = "event" id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(50), index = True) description = db.Column(db.String(100), nullable = True) organizer_id = db.Column(db.Integer, db.ForeignKey("organizer.id", onupdate = "CASCADE", ondelete = "CASCADE")) event_type_id = db.Column(db.Integer, db.ForeignKey("event_type.id", onupdate = "CASCADE", ondelete = "CASCADE")) event_venue_id = db.Column(db.Integer, db.ForeignKey("event_venue.id", onupdate = "CASCADE", ondelete = "CASCADE")) start_date = db.Column(db.DateTime(), nullable = False) end_date = db.Column(db.DateTime(), nullable = False) deleted = db.Column(db.Boolean, default = 0) created = db.Column(db.DateTime(), default = datetime.now) updated = db.Column(db.DateTime(), onupdate = datetime.now) organizer = db.relationship('Organizer', backref = backref("event", uselist = False)) venue = db.relationship('EventVenue', backref = backref("event", uselist = False)) type = db.relationship('EventType', backref = backref("event", uselist = False)) def __repr__(self): return "Event: " + format(self)
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255)) password = db.Column(db.String(255)) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) tos_agreed = db.Column(db.Boolean) created_at = db.Column(db.DateTime(False)) modified_at = db.Column(db.DateTime(False)) def __init__(self, username, password, first_name, last_name): self.username = username self.password = password self.first_name = first_name self.last_name = last_name def save_to_db(self): db.session.add(self) db.session.commit() @classmethod def find_by_username(cls, username): return cls.query.filter_by(username=username).first() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first()
class BaseModel(db.Model): __abstract__ = True id = db.Column( db.Integer, primary_key=True, ) created_at = db.Column(db.DateTime(timezone=True), default=generate_current_time) updated_at = db.Column(db.DateTime(timezone=True), nullable=True) @declared_attr def __tablename__(cls): return cls.__name__ def save(self, commit=True): db.session.add(self) self._commit_or_flush(commit) def update(self): db.session.commit() def delete(self, commit=True): db.session.delete(self) self._commit_or_flush(commit) @classmethod def _commit_or_flush(cls, commit): if commit: db.session.commit() else: db.session.flush()
class ItemModel(db.Model): __tablename__ = "Items" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) produce_date = db.Column(db.DateTime(), default=True) expire_date = db.Column(db.DateTime(), default=True) price = db.Column(db.Float(precision=5)) store_id = db.Column(db.Integer, db.ForeignKey('Stores.id')) store = db.relationship('StoreModel') def __init__(self, _id, name, price, store_id): self.id = _id self.name = name self.price = price self.store_id = store_id def to_Json(self): return { 'id': self.id, 'name': self.name, 'price': self.price, 'store': self.store.to_JsonNoItems() } @classmethod def get_Item_By_Name(cls, name): try: return cls.query.filter_by( name=name).first() # Replacing ItemModel with cls except: raise def insertItem(self): try: db.session.add(self) db.session.commit() return self except: raise @classmethod def getAllItems(cls): try: return cls.query.all() except: raise def deleteItem(self): try: db.session.delete(self) db.session.commit() except: raise def updateItem(self): try: db.session.add(self) db.session.commit() except: raise
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80)) first_name = db.Column(db.String(80)) last_name = db.Column(db.String(80)) password = db.Column(db.String(80)) user_created = db.Column(db.DateTime(), nullable=False, default=datetime.utcnow()) user_updated = db.Column(db.DateTime(), nullable=False, default=datetime.utcnow()) def __init__(self, username, first_name, last_name, password, user_created): self.username = username self.first_name = first_name self.last_name = last_name self.password = password self.user_created = user_created def json(self): return {'username': self.username, 'first_name': self.first_name, 'last_name': self.last_name, 'password': self.password, 'user_created': self.user_created.strftime('%Y-%m-%d %H:%M:%S')} def upd_json(self): return {'username': self.username, 'first_name': self.first_name, 'last_name': self.last_name, 'password': self.password, 'user_created': self.user_created.strftime('%Y-%m-%d %H:%M:%S'), 'user_updated': self.user_updated.strftime('%Y-%m-%d %H:%M:%S')} def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) @classmethod def find_by_username(cls, username): return cls.query.filter_by(username=username).first() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class Courses(db.Model): __tablename__ = 'courses' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(16)) student_enrolled = db.Column(db.Integer) is_active = db.Column(db.Boolean()) created_datetime = db.Column(db.DateTime(), nullable=False) modified_datetime = db.Column(db.DateTime(), nullable=False)
class Sheep_Model(db.Model): __tablename__ = "sheeps" id = db.Column(db.Integer, primary_key=True) farms_id = db.Column(db.Integer, db.ForeignKey('farms.id'), nullable=False) earring = db.Column(db.String(50), nullable=False) earring_color = db.Column(db.String(20), nullable=False) gender = db.Column(db.String(2), nullable=False) breed = db.Column(db.String(80), nullable=False) birth_weight = db.Column(db.Float, default=0, nullable=False) date_birth = db.Column(db.DateTime()) purpose = db.Column(db.String(50)) category = db.Column(db.String(20), nullable=False) merit = db.Column(db.Integer, default=0, nullable=False) is_dead = db.Column(db.String(2), default=False, nullable=False) creation_date = db.Column(db.DateTime(), default=datetime.now()) sickness = db.relationship('Sanitary_Model', backref='sheep') relations = db.relationship('Sheeps_Filiations_Model', backref='sheep') def __init__(self, earring, earring_color, gender, breed, birth_weight, date_birth, purpose, category, merit, is_dead, farms_id): self.earring = earring self.earring_color = earring_color self.gender = gender self.breed = breed self.birth_weight = birth_weight self.date_birth = date_birth self.purpose = purpose self.category = category self.merit = merit self.is_dead = is_dead self.farms_id = farms_id def save_to_db(self): db.session.add(self) db.session.commit() def json(self): return { '_id': self.id, 'earring': self.earring, 'earring_color': self.earring_color, 'gender': self.gender, 'breed': self.breed, 'birth_weight': self.birth_weight, 'date_birth': self.date_birth, 'purpose': self.purpose, 'category': self.category, 'merit': self.merit, 'is_dead': self.is_dead } @classmethod def get_all(cls): return [sheep.json() for sheep in cls.query.all()]
class Base(db.Model, DataFrameMixin): """ Data model base class """ __abstract__ = True _columns: ColumnProxy = None # type: ignore _agg: AggregateProxy = None # type: ignore _pk: PrimaryKeyProxy = None # type: ignore created_at = db.Column( db.DateTime(timezone=True), default=utcnow, server_default=db.func.now(), ) updated_at = db.Column( db.DateTime(timezone=True), default=utcnow, onupdate=utcnow, server_default=db.func.now(), index=True, ) def __repr__(self): return util.jsontools.make_repr(self) @classproperty def c(cls) -> ColumnProxy: return cls.columns @classproperty def columns(cls) -> ColumnProxy: if not cls._columns: cls._columns = ColumnProxy(cls) return cls._columns @classproperty def agg(cls) -> AggregateProxy: if not cls._agg: cls._agg = AggregateProxy(cls) return cls._agg @classproperty def pk(cls) -> PrimaryKeyProxy: if not cls._pk: cls._pk = PrimaryKeyProxy(cls) return cls._pk @classproperty def __model_name__(cls) -> str: return f"{cls.__module__}.{cls.__name__}" @classproperty def constraints(cls) -> Dict[str, Constraint]: return {x.name: x for x in list(cls.__table__.constraints)}
class Shift(db.Model): __tablename__ = "shift" id = db.Column(db.Integer, primary_key=True) bgn_hour = db.Column(db.DateTime()) end_hour = db.Column(db.DateTime()) office_id = db.Column(db.Integer, db.ForeignKey('office.id')) doctor_id = db.Column(db.Integer, db.ForeignKey('doctor.id')) def __init__(self, bgn_hour, end_hour, office_id, doctor_id): self.bgn_hour = bgn_hour self.end_hour = end_hour self.office_id = office_id self.doctor_id = doctor_id
class CategoryModel(db.Model): __tablename__ = 'categories' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), unique=True) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) fr_label = db.Column(db.String(255)) en_label = db.Column(db.String(255)) picture = db.Column(db.String(255)) def __init__(self, name, fr_label, en_label, picture): self.name = name self.created_at = datetime.utcnow() self.updated_at = datetime.utcnow() self.fr_label = fr_label self.en_label = en_label self.picture = picture def save(self): db.session.add(self) db.session.commit() def update(self, **kwargs): self.name = kwargs['name'] self.fr_label = kwargs['fr_label'] self.en_label = kwargs['en_label'] self.picture = kwargs['picture'] self.updated_at = datetime.utcnow() db.session.commit() def delete(self): db.session.delete(self) db.session.commit() def json(self): return { "id": self.id, "category_name": self.name, "created_at": self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), "updated_at": self.updated_at.strftime('%Y-%m-%dT%H:%M:%S'), "french_label": self.fr_label, "english_label": self.en_label, "picture_url": self.picture, "courses": [course.json() for course in self.courses] } @classmethod def find_by_id(cls, category_id): return cls.query.filter_by(id=category_id).first()
class EventType(db.Model): """ Event Type Table """ __tablename__ = "event_type" id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(50), unique = True) description = db.Column(db.String(100), nullable = True) created = db.Column(db.DateTime(), default = datetime.now) updated = db.Column(db.DateTime(), onupdate = datetime.now) def __repr__(self): return "EventType: " + format(self)
class Show(db.Model): __tablename__ = 'shows' id = db.Column(db.Integer, primary_key=True) start_time = db.Column(db.DateTime(), nullable=False) venue_id = db.Column(db.Integer, db.ForeignKey('venues.id'), nullable=False) artist_id = db.Column(db.Integer, db.ForeignKey('artists.id'), nullable=False) @property def show_details(self): from models.utils import get_artist_details, get_venue_details venue = get_venue_details(self.venue_id) artist = get_artist_details(self.artist_id) return { 'venue_id': self.venue_id, 'venue_name': venue.name, 'artist_id': self.artist_id, 'artist_name': artist.name, 'artist_image_link': artist.image_link, 'start_time': self.start_time.strftime("%m/%d/%Y, %H:%M") }
class MeasurementModel(db.Model): __tablename__ = "measures" id = db.Column(db.Integer, primary_key=True) timestamp = db.Column(db.DateTime(), nullable=False) location = db.Column(db.String(80), nullable=False) measurement = db.Column(db.String(80), nullable=False) value = db.Column(db.Float(precision=2), nullable=False) unit = db.Column(db.String(30), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) user = db.relationship("UserModel") def save_to_db(self) -> None: """ :cvar """ db.session.add(self) db.session.commit() def delete_from_db(self) -> None: """ :param """ db.session.delete(self) db.session.commit() @classmethod def find_by_location(cls, location) -> List["MeasurementModel"]: print(f"Find by location called for: {location}") return cls.query.filter_by(location=location).all() @classmethod def find_by_id(cls, _id) -> "MeasurementModel": return cls.query.filter_by(id=_id).first()
class Sheeps_Filiations_Model(db.Model): __tablename__ = "sheeps_filiations" id = db.Column(db.Integer, primary_key=True) sheep_id = db.Column(db.Integer, db.ForeignKey('sheeps.id'), nullable=False) filiation_id = db.Column(db.Integer, db.ForeignKey('filiations.id'), nullable=False) relationship = db.Column(db.String(15), nullable=False) creation_date = db.Column(db.DateTime(), default=datetime.now()) def __init__(self, relationship): self.relationship = relationship def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first()
class Users_Farms_Model(db.Model): __tablename__ = "users_farms" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) farms_id = db.Column(db.Integer, db.ForeignKey('farms.id'), nullable=False) can_edit = db.Column(db.String(10), default="F", nullable=False) can_see = db.Column(db.String(10), default="T", nullable=False) super_user = db.Column(db.String(10), default="F", nullable=False) creation_date = db.Column(db.DateTime(), default=datetime.now()) def __init__(self, can_edit, can_see, super_user, user_id, farms_id): self.can_edit = can_edit self.can_see = can_see self.super_user = super_user self.user_id = user_id self.farms_id = farms_id def save_to_db(self): db.session.add(self) db.session.commit() def json(self): return { 'can_edit': self.can_edit, 'can_see': self.can_see, 'super_user': self.super_user } @classmethod def get_alls(cls): return [farm.json() for farm in cls.query.all()]
class SafeEventModel(db.Model): __tablename__ = 'safe_event' hardware_id = db.Column(db.String(64), db.ForeignKey("safe.hardware_id"), primary_key=True) timestamp = db.Column(db.DateTime(), primary_key=True) event_code = db.Column(db.Integer, nullable=False) detail = db.Column(db.String(40), nullable=False) safe = db.relationship("SafeModel") def save_to_db(self) -> None: """ :cvar """ db.session.add(self) db.session.commit() @classmethod def find_all(cls) -> List["SafeEventModel"]: """ :return: """ return cls.query.all()
class PurchaseModel(db.Model): __tablename__ = 'purchase' id = db.Column(db.Integer, primary_key=True) price = db.Column(db.Float(precision=2), nullable=False) quantity = db.Column(db.Integer, nullable=False) purchase_date = db.Column(db.DateTime(timezone=True), nullable=False) company_id = db.Column(db.Integer, db.ForeignKey('company.id')) company = db.relationship('CompanyModel') def __init__(self, price, quantity, company_id, purchase_date): self.price = price self.quantity = quantity self.company_id = company_id self.purchase_date = purchase_date def json(self): if self.purchase_date is None: purchase_date_out = None else: purchase_date_out = datetime.strftime(self.purchase_date, "%Y-%m-%d") return {'price': self.price, 'quantity': self.quantity, 'purchase_date': purchase_date_out} def save(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class User(db.Model): """ User model have a one-to-many relationship to Link """ id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(32), unique=True) password_hash = db.Column(db.String(128)) links = db.relationship('Link', backref='owner', cascade="all, delete-orphan") time_created = db.Column(db.DateTime(timezone=True), server_default=func.now()) time_profile_updated = db.Column(db.DateTime) is_public = db.Column(db.Boolean, default=USER_PUBLICITY) time_new_link_added = db.Column(db.DateTime) def __init__(self, **kwargs): super().__init__(**kwargs) self.password_hash = generate_password_hash(self.password_hash) def check_password(self, password): return check_password_hash(self.password_hash, password) def update_password(self, new_password: str): self.password_hash = generate_password_hash(new_password)
class AccountModel(UserMixin, db.Model, BaseModel): __tablename__ = 'accounts' id = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String(50)) lastname = db.Column(db.String(50)) email = db.Column(db.String(100), unique=True, nullable=False) password = db.Column(db.String(200)) role = db.Column(db.String(200)) created_at = db.Column(db.DateTime(timezone=True), default=func.now()) updated_at = db.Column(db.DateTime(timezone=True), onupdate=func.now()) deleted_at = db.Column(db.DateTime(timezone=True)) @classmethod def encrypt_password(cls, password): return generate_password_hash(password, method='sha256')
class ReturnRequestModel(db.Model): __tablename__ = "return_requests" id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime(), nullable=False) sent_by = db.Column(db.Integer, nullable=False) received_by = db.Column(db.Integer, nullable=False) book_id = db.Column(db.Integer, db.ForeignKey("books.id"), nullable=False) book = db.relationship("BookModel", back_populates="return_requests") @classmethod def find_by_received_id(cls, user_id): return cls.query.filter_by(received_by=user_id).all() @classmethod def find_by_book_id(cls, book_id): return cls.query.filter_by(book_id=book_id).first() @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class Following(db.Model): __tablename__ = 'following' id = db.Column(db.Integer, primary_key=True) follower_id = db.Column(db.Integer) following_id = db.Column(db.Integer) followed_at = db.Column(db.DateTime()) __table_args__ = (UniqueConstraint('follower_id', 'following_id', name='_follower_following_uc'), ) def __init__(self, follower_id, following_id, followed_at): self.follower_id = follower_id self.following_id = following_id self.followed_at = followed_at def __repr__(self): return '<id {}>'.format(self.id) def serialize(self): return { 'id': self.id, 'follower_id': self.follower_id, 'following_id': self.following_id, 'followed_at': self.followed_at }
class NewsModel(db.Model): __tablename__ = "news" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80), unique=True, nullable=False) text = db.Column(db.String(), unique=True, nullable=False) date = db.Column(db.DateTime(), default=datetime.now(), nullable=False)
class Farms_Model(db.Model): __tablename__ = "farms" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) latitude = db.Column(db.String(10)) longitude = db.Column(db.String(10)) creation_date = db.Column(db.DateTime(), default=datetime.now()) users = db.relationship('Users_Farms_Model', backref=db.backref('farm', lazy=True)) sheeps = db.relationship('Sheep_Model', backref=db.backref('farm', lazy=True)) def __init__(self, name, latitude, longitude): self.name = name self.latitude = latitude self.longitude = longitude def save_to_db(self): db.session.add(self) db.session.commit() def json(self): return { 'id': self.id, 'name': self.name, 'latitude': self.latitude, 'longitude': self.longitude }
class IncomeModel(db.Model): __tablename__ = 'income' id = db.Column(db.Integer, primary_key=True) receive_date = db.Column(db.DateTime(timezone=True), nullable=False) value = db.Column(db.Float(precision=2), nullable=False) income_type = db.Column(db.String(3), nullable=False) company_id = db.Column(db.Integer, db.ForeignKey('company.id')) company = db.relationship('CompanyModel') def __init__(self, value, income_type, company_id, receive_date): self.receive_date = receive_date self.value = value self.income_type = income_type self.company_id = company_id def json(self): if self.receive_date is None: receive_date_out = None else: receive_date_out = datetime.strftime(self.receive_date, "%Y-%m-%d") return { 'value': self.value, 'income_type': self.income_type, 'receive_date': receive_date_out } def save(self): db.session.add(self) db.session.commit()
class User(db.Model, UserMixin): """ User Class """ id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) def __init__(self, **kwargs): self.__dict__.update(kwargs) self.password = utils.hash_password(self.password) def edit_update(self, form): self.first_name = form.first_name.data self.last_name = form.last_name.data self.email = form.email.data self.password = utils.hash_password(form.password.data) def __str__(self): return self.email def is_active(self): return self.active def __unicode__(self): return self.first_name
class Tweet(db.Model): tweet_id = db.Column(db.Integer, primary_key=True) tweet_text = db.Column(db.String(140)) user = db.Column(db.String(140)) timestamp = db.Column(db.DateTime()) created = db.Column(db.DateTime()) def __init__(self, tweet): self.tweet_id = tweet['id'] self.tweet_text = tweet['text'] self.user = tweet['user']['screen_name'] self.timestamp = datetime.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y') self.created = datetime.now() def __repr__(self): return '<Tweet {}>'.format(self.tweet_id)
class Organizer(db.Model): """ Event organizer Table """ __tablename__ = "organizer" id = db.Column(db.Integer, primary_key = True) first_name = db.Column(db.String(50)) last_name = db.Column(db.String(50)) email = db.Column(db.String(50)) phone_number = db.Column(db.String(20)) created = db.Column(db.DateTime(), default = datetime.now) updated = db.Column(db.DateTime(), onupdate = datetime.now) def __repr__(self): return "Organizer: " + format(self)
class Stat(dbs.Model): """ This model is the main Stat model. For non time consuming development reasons, only One-to-One relations are set. The created time is set server-side. """ __tablename__ = 'stat' id = dbs.Column(dbs.Integer, primary_key=True) shortcodeId = dbs.Column(dbs.Integer, dbs.ForeignKey('shortcode.id')) shortcode = dbs.relationship('Shortcode', back_populates='stats', foreign_keys=[shortcodeId]) created = dbs.Column(dbs.DateTime(timezone=True), server_default=func.strftime('%Y-%m-%d %H:%M:%f', 'now')) redirect = dbs.relationship('Redirect', back_populates='stat', uselist=False) @classmethod def get_stats(cls, shortcode): """ This method retrieves the stats for the provided shortcode. :param shortcode: The provided shortcode. :type shortcode: str :return: The fetched stats for the provided shortcode. :rtype: dict .. note:: As the Redirect child for a stat is created in a non-greedy way, the logic handling for a not existing Redirect is handled in this method. :raises: ShortcodeNotFound: When the provided shortcode does not exist. """ in_use = Shortcode.check_in_use(shortcode=shortcode) if in_use is False: raise ShortcodeNotFound _stat = cls.query.filter( cls.shortcode.has(shortcode=shortcode)).first() if _stat.redirect is None: last_redirect = None redirect_count = 0 else: last_redirect = _stat.redirect.lastRedirect.isoformat() redirect_count = _stat.redirect.redirectCount return { cls.created.name: _stat.created.isoformat(), Redirect.lastRedirect.name: last_redirect, Redirect.redirectCount.name: redirect_count }
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) # User email information email = db.Column(db.String(255), nullable=False, unique=True) confirmed_at = db.Column(db.DateTime()) # User information is_enabled = db.Column(db.Boolean(), nullable=False, default=False) first_name = db.Column(db.String(50), nullable=False, default='') last_name = db.Column(db.String(50), nullable=False, default='') birth_year = db.Column(db.Integer(), nullable=False) # User authentication information username = db.Column(db.String(50), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False, default='') # meters = db.relationship('Meter', backref='owner', lazy='dynamic') def __init__(self, email, username, password, first_name, last_name, birth_year): self.email = email self.username = username self.set_password(password) self.first_name = first_name self.last_name = last_name self.birth_year = birth_year @classmethod def find_by_username(cls, username): return cls.query.filter_by(username=username).first() @classmethod def find_by_email(cls, email): return cls.query.filter_by(email=email).first() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() def save_to_db(self): db.session.add(self) db.session.commit() def is_active(self): return self.is_enabled def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def json(self): return {'username': self.username, 'email': self.email}
class Agreement(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) email = db.Column(db.String(120)) signature = db.Column(db.Text) contract_id = db.Column(db.Integer, db.ForeignKey('contract.id')) contract = db.relationship('Contract', backref=db.backref('agreements', lazy='dynamic')) created_at = db.Column(db.DateTime(), default=datetime.datetime.now) updated_at = db.Column(db.DateTime()) def __repr__(self): return '<Agreement %r>' % self.email def save(self, *args, **kwargs): self.updated_at = datetime.datetime.now return super(Agreement, self).save(*args, **kwargs)