You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.9 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'
#Auto Fiels
id = db.Column(db.Integer, nullable=False, primary_key=True)
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)
#Own Fields
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')
#RELATIONSHIPS
# 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')
# to Device
manufactured_devices= db.relationship("nbiotDevice", foreign_keys="nbiotDevice.company_manufacturer_id", back_populates="company_manufacturer")
owned_devices = db.relationship("nbiotDevice", foreign_keys="nbiotDevice.company_owner_id", back_populates="company_owner")
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}"