generated from daniil-berg/boilerplate-py
Add some models; minor changes
This commit is contained in:
parent
9f487d515d
commit
3f6be9adbc
@ -20,6 +20,7 @@ __all__ = [
|
|||||||
'LegalForm',
|
'LegalForm',
|
||||||
'LegalFormSubcategory',
|
'LegalFormSubcategory',
|
||||||
'Industry',
|
'Industry',
|
||||||
|
'Executive',
|
||||||
'Company',
|
'Company',
|
||||||
'CompanyName',
|
'CompanyName',
|
||||||
]
|
]
|
||||||
@ -66,13 +67,21 @@ class LegalFormSubcategory(AbstractBase, table=True):
|
|||||||
|
|
||||||
|
|
||||||
class CompanyIndustryLink(AbstractBase, table=True):
|
class CompanyIndustryLink(AbstractBase, table=True):
|
||||||
__tablename__ = 'company_industries'
|
__tablename__ = 'company_industry'
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
company_id: Optional[int] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
|
company_id: Optional[int] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
|
||||||
industry_id: Optional[int] = Field(foreign_key='industry.id', default=None, nullable=False, primary_key=True)
|
industry_id: Optional[int] = Field(foreign_key='industry.id', default=None, nullable=False, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyExecutiveLink(AbstractBase, table=True):
|
||||||
|
__tablename__ = 'company_executive'
|
||||||
|
|
||||||
|
# Relationships
|
||||||
|
company_id: Optional[int] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
|
||||||
|
executive_id: Optional[int] = Field(foreign_key='executive.id', default=None, nullable=False, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class Industry(AbstractBase, table=True):
|
class Industry(AbstractBase, table=True):
|
||||||
__tablename__ = 'industry'
|
__tablename__ = 'industry'
|
||||||
|
|
||||||
@ -88,6 +97,24 @@ class Industry(AbstractBase, table=True):
|
|||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
class Executive(AbstractBase, table=True):
|
||||||
|
__tablename__ = 'executive'
|
||||||
|
__MAX_LENGTH_NAME__: int = 255
|
||||||
|
|
||||||
|
# Fields
|
||||||
|
name: str = Field(
|
||||||
|
max_length=__MAX_LENGTH_NAME__, sa_column=Column(Unicode(__MAX_LENGTH_NAME__), nullable=False, index=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Relationships
|
||||||
|
companies: list['Company'] = Relationship(
|
||||||
|
back_populates='executives', link_model=CompanyExecutiveLink, sa_relationship_kwargs={'lazy': 'selectin'}
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return str(self.name)
|
||||||
|
|
||||||
|
|
||||||
class Company(AbstractBase, table=True):
|
class Company(AbstractBase, table=True):
|
||||||
__tablename__ = 'company'
|
__tablename__ = 'company'
|
||||||
|
|
||||||
@ -96,7 +123,8 @@ class Company(AbstractBase, table=True):
|
|||||||
insolvent: bool = Field(default=False, nullable=False, index=True)
|
insolvent: bool = Field(default=False, nullable=False, index=True)
|
||||||
founding_data: Optional[date]
|
founding_data: Optional[date]
|
||||||
liquidation_date: Optional[date]
|
liquidation_date: Optional[date]
|
||||||
city: str = Field(max_length=255, index=True) # TODO: Get rid of city; implement address properly
|
# TODO: Get rid of city; implement address properly
|
||||||
|
city: Optional[str] = Field(max_length=255, nullable=True, index=True)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
legal_form_id: Optional[int] = Field(
|
legal_form_id: Optional[int] = Field(
|
||||||
@ -114,6 +142,10 @@ class Company(AbstractBase, table=True):
|
|||||||
back_populates='companies', link_model=CompanyIndustryLink, sa_relationship_kwargs={'lazy': 'selectin'}
|
back_populates='companies', link_model=CompanyIndustryLink, sa_relationship_kwargs={'lazy': 'selectin'}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
executives: list[Executive] = Relationship(
|
||||||
|
back_populates='companies', link_model=CompanyExecutiveLink, sa_relationship_kwargs={'lazy': 'selectin'}
|
||||||
|
)
|
||||||
|
|
||||||
names: list['CompanyName'] = Relationship(
|
names: list['CompanyName'] = Relationship(
|
||||||
back_populates='company', sa_relationship_kwargs={'lazy': 'selectin'}
|
back_populates='company', sa_relationship_kwargs={'lazy': 'selectin'}
|
||||||
)
|
)
|
||||||
@ -128,12 +160,12 @@ class Company(AbstractBase, table=True):
|
|||||||
|
|
||||||
class CompanyName(AbstractBase, table=True):
|
class CompanyName(AbstractBase, table=True):
|
||||||
__tablename__ = 'company_name'
|
__tablename__ = 'company_name'
|
||||||
__MAX_NAME_LENGTH__: int = 768
|
__MAX_LENGTH_NAME__: int = 768
|
||||||
__MAX_SLUG_LENGTH__: int = 255
|
__MAX_SLUG_LENGTH__: int = 255
|
||||||
|
|
||||||
# Fields
|
# Fields
|
||||||
name: str = Field(
|
name: str = Field(
|
||||||
max_length=__MAX_NAME_LENGTH__, sa_column=Column(Unicode(__MAX_NAME_LENGTH__), nullable=False, index=True)
|
max_length=__MAX_LENGTH_NAME__, sa_column=Column(Unicode(__MAX_LENGTH_NAME__), nullable=False, index=True)
|
||||||
)
|
)
|
||||||
date_registered: Optional[date]
|
date_registered: Optional[date]
|
||||||
slug: Optional[str] = Field(default=None, max_length=__MAX_SLUG_LENGTH__, index=True)
|
slug: Optional[str] = Field(default=None, max_length=__MAX_SLUG_LENGTH__, index=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user