miniBase/web/minibase/blueprints/company/models.py

83 lines
3.5 KiB

from minibase.app import db
from datetime import datetime
from minibase.blueprints.geography.models import Country, City, State
from minibase.blueprints.main.models import Industries, Notes
class Companies(db.Model):
__tablename__ = 'companies'
id = db.Column(db.Integer, nullable=False, primary_key=True)
name = db.Column(db.String(100), nullable=False)
website = db.Column(db.String(100), nullable=True, default='')
street = db.Column(db.String(100), nullable=False)
street_no = db.Column(db.Integer, nullable=False)
post_code = db.Column(db.Integer, nullable=False)
comment = db.Column(db.String(300), nullable=True)
image_file = db.Column(db.String(20), nullable=False, default='def_company_avatar.png')
upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
# One To Many Relationship
legal_entity_id = db.Column(db.Integer, db.ForeignKey('company_legal_entities.id'), nullable=False)
type_id = db.Column(db.Integer, db.ForeignKey('company_types.id'), nullable=False)
relation_id = db.Column(db.Integer, db.ForeignKey('company_relations.id'), nullable=False)
status_id = db.Column(db.Integer, db.ForeignKey('company_status.id'), nullable=False)
industry_id = db.Column(db.Integer, db.ForeignKey('industries.id'), nullable=False)
country_id = db.Column(db.Integer, db.ForeignKey('countries.id'), nullable=False)
state_id = db.Column(db.Integer, db.ForeignKey('states.id'), nullable=False)
city_id = db.Column(db.Integer, db.ForeignKey('cities.id'), nullable=False)
# Many To one
notes = db.relationship('Notes', backref='company_notes', lazy='dynamic')
class Company_types(db.Model):
__tablename__ = 'company_types'
id = db.Column(db.Integer, nullable=False, primary_key=True)
name = db.Column(db.String(50), nullable=False)
description = db.Column(db.String(300), nullable=False)
companies = db.relationship('Companies', backref='type', lazy='dynamic')
def __repr__(self):
return f"{self.name}"
class Company_legal_entities(db.Model):
__tablename__ = 'company_legal_entities'
id = db.Column(db.Integer, nullable=False, primary_key=True)
name = db.Column(db.String(50), nullable=False)
description = db.Column(db.String(300), nullable=False)
companies = db.relationship('Companies', backref='legal_entity', lazy='dynamic')
# returns a more information-rich, or official, string representation of an object
def __repr__(self):
return f"{self.name}"
class Company_status(db.Model):
__tablename__ = 'company_status'
id = db.Column(db.Integer, nullable=False, primary_key=True)
name = db.Column(db.String(50), nullable=False)
description = db.Column(db.String(300), nullable=False)
companies = db.relationship('Companies', backref='status', lazy='dynamic')
# returns a more information-rich, or official, string representation of an object
def __repr__(self):
return f"{self.name}"
class Company_relations(db.Model):
__tablename__ = 'company_relations'
id = db.Column(db.Integer, nullable=False, primary_key=True)
name = db.Column(db.String(50), nullable=False)
description = db.Column(db.String(300), nullable=False)
companies = db.relationship('Companies', backref='relation', lazy='dynamic')
# returns a more information-rich, or official, string representation of an object
def __repr__(self):
return f"{self.name}"