30 lines
755 B
Python
30 lines
755 B
Python
from beanie import PydanticObjectId
|
|
from pydantic import Field, BaseModel
|
|
from pymongo import IndexModel
|
|
|
|
from hub import CrudDocument
|
|
|
|
class Firm(CrudDocument):
|
|
name: str = Field()
|
|
instance: str = Field()
|
|
owner: PydanticObjectId = Field()
|
|
|
|
def compute_label(self) -> str:
|
|
return self.name
|
|
|
|
class Settings:
|
|
indexes = [
|
|
IndexModel(["name", "instance"], unique=True),
|
|
]
|
|
|
|
class FirmRead(BaseModel):
|
|
instance: str = Field()
|
|
name: str = Field()
|
|
|
|
class FirmCreate(FirmRead):
|
|
instance: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
|
name: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
|
|
|
class FirmUpdate(BaseModel):
|
|
owner: PydanticObjectId = Field()
|