34 lines
909 B
Python
34 lines
909 B
Python
from beanie import PydanticObjectId
|
|
from pydantic import Field, BaseModel
|
|
from pymongo import IndexModel
|
|
|
|
from hub.core import CrudDocument
|
|
|
|
class Firm(CrudDocument):
|
|
instance: str = Field()
|
|
firm: str = Field()
|
|
owner: PydanticObjectId = Field()
|
|
|
|
@classmethod
|
|
def get_by_name(cls, instance, firm):
|
|
return cls.find_one({"instance": instance, "firm": firm})
|
|
|
|
def compute_label(self) -> str:
|
|
return f"{self.instance} / {self.firm}"
|
|
|
|
class Settings:
|
|
indexes = [
|
|
IndexModel(["instance", "firm"], unique=True),
|
|
]
|
|
|
|
class FirmRead(BaseModel):
|
|
instance: str = Field()
|
|
firm: str = Field()
|
|
|
|
class FirmCreate(FirmRead):
|
|
instance: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
|
firm: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
|
|
|
class FirmUpdate(BaseModel):
|
|
owner: PydanticObjectId = Field()
|