Adjustements everywhere
This commit is contained in:
@@ -15,10 +15,10 @@ class EntityType(BaseModel):
|
||||
|
||||
class Individual(EntityType):
|
||||
type: Literal['individual'] = 'individual'
|
||||
firstname: Indexed(str, index_type=TEXT)
|
||||
middlenames: List[Indexed(str)] = Field(default=[])
|
||||
firstname: Indexed(str)
|
||||
middlename: Indexed(str) = ""
|
||||
lastname: Indexed(str)
|
||||
surnames: List[Indexed(str)] = Field(default=[])
|
||||
surnames: List[Indexed(str)] = []
|
||||
day_of_birth: date
|
||||
|
||||
|
||||
@@ -29,15 +29,8 @@ class Individual(EntityType):
|
||||
|
||||
return '{} {}'.format(self.firstname, self.lastname)
|
||||
|
||||
@staticmethod
|
||||
def get_label(data) -> str:
|
||||
if len(data['surname']) > 0:
|
||||
return '{} "{}" {}'.format(data['firstname'], data['surnames'][0], data['lastname'])
|
||||
|
||||
return '{} {}'.format(data['firstname'], data['lastname'])
|
||||
|
||||
|
||||
class Employee(EntityType):
|
||||
class Employee(BaseModel):
|
||||
role: Indexed(str)
|
||||
entity_id: str = Field(foreignKey={
|
||||
"reference": {
|
||||
@@ -55,7 +48,7 @@ class Corporation(EntityType):
|
||||
employees: List[Employee] = Field(default=[])
|
||||
|
||||
|
||||
class Institution(BaseModel):
|
||||
class Institution(EntityType):
|
||||
type: Literal['institution'] = 'institution'
|
||||
title: Indexed(str)
|
||||
activity: Indexed(str)
|
||||
@@ -70,6 +63,8 @@ class Entity(Document):
|
||||
|
||||
@validator("label", always=True)
|
||||
def generate_label(cls, v, values, **kwargs):
|
||||
if 'entity_data' not in values:
|
||||
return v
|
||||
return values['entity_data'].label
|
||||
|
||||
created_at: datetime = Field(default=datetime.utcnow(), nullable=False)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from .models import Entity, EntityType, Individual, Corporation
|
||||
from .models import Entity, Institution, Individual, Corporation
|
||||
from ..core.schemas import Writer
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ class EntityRead(Entity):
|
||||
|
||||
|
||||
class EntityCreate(Writer):
|
||||
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
address: Optional[str] = ""
|
||||
|
||||
|
||||
class EntityUpdate(BaseModel):
|
||||
entity_data: Individual | Corporation = Field(..., discriminator='type')
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
address: Optional[str] = ""
|
||||
|
||||
@@ -19,7 +19,7 @@ async def handle_migration(args):
|
||||
content = json.load(f)
|
||||
for r in content:
|
||||
obj = m(**r)
|
||||
obj.save()
|
||||
await obj.save()
|
||||
|
||||
elif args.action == "export-fixtures":
|
||||
for m in models:
|
||||
|
||||
Reference in New Issue
Block a user