minor improvements
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from enum import Enum
|
||||
from datetime import datetime, date
|
||||
from datetime import date, datetime
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from pymongo import TEXT, IndexModel
|
||||
from pydantic import Field, BaseModel, validator
|
||||
from beanie import Document, Indexed
|
||||
|
||||
from ..core.models import CrudDocument
|
||||
|
||||
|
||||
class EntityType(BaseModel):
|
||||
@property
|
||||
@@ -55,11 +57,10 @@ class Institution(EntityType):
|
||||
employees: List[Employee] = Field(default=[])
|
||||
|
||||
|
||||
class Entity(Document):
|
||||
_id: str
|
||||
class Entity(CrudDocument):
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
address: Optional[str] = ""
|
||||
label: str = None
|
||||
address: Optional[str] = ""
|
||||
|
||||
@validator("label", always=True)
|
||||
def generate_label(cls, v, values, **kwargs):
|
||||
@@ -67,16 +68,11 @@ class Entity(Document):
|
||||
return v
|
||||
return values['entity_data'].label
|
||||
|
||||
created_at: datetime = Field(default=datetime.utcnow(), nullable=False)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
|
||||
|
||||
class Settings:
|
||||
bson_encoders = {
|
||||
date: lambda dt: dt if hasattr(dt, 'hour')
|
||||
else datetime(year=dt.year, month=dt.month, day=dt.day,
|
||||
hour=0, minute=0, second=0)
|
||||
}
|
||||
|
||||
class Settings(CrudDocument.Settings):
|
||||
fulltext_search = ['label']
|
||||
|
||||
|
||||
bson_encoders = {
|
||||
date: lambda dt: dt if hasattr(dt, 'hour')
|
||||
else datetime(year=dt.year, month=dt.month, day=dt.day,
|
||||
hour=0, minute=0, second=0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user