Initializing multitenant
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from datetime import date, datetime
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from pydantic import Field, BaseModel, validator
|
||||
from pydantic import Field, BaseModel
|
||||
from beanie import Indexed
|
||||
|
||||
from ..core.models import CrudDocument
|
||||
from ..core.filter import Filter
|
||||
|
||||
|
||||
class EntityType(BaseModel):
|
||||
@@ -75,14 +76,12 @@ class Entity(CrudDocument):
|
||||
Fiche d'un client
|
||||
"""
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
label: str = None
|
||||
address: str = Field(default="", title='Adresse')
|
||||
|
||||
@validator("label", always=True)
|
||||
def generate_label(cls, v, values, **kwargs):
|
||||
if 'entity_data' not in values:
|
||||
return v
|
||||
return values['entity_data'].label
|
||||
def compute_label(self) -> str:
|
||||
if not self.entity_data:
|
||||
return ""
|
||||
return self.entity_data.label
|
||||
|
||||
class Settings(CrudDocument.Settings):
|
||||
fulltext_search = ['label']
|
||||
@@ -96,6 +95,12 @@ class Entity(CrudDocument):
|
||||
class Config:
|
||||
title = 'Client'
|
||||
|
||||
@classmethod
|
||||
def get_create_resource(cls):
|
||||
print('coucou')
|
||||
|
||||
class EntityFilters(Filter):
|
||||
name__like: Optional[str] = None
|
||||
|
||||
order_by: Optional[list[str]] = None
|
||||
|
||||
class Constants(Filter.Constants):
|
||||
model = Entity
|
||||
search_model_fields = ["name"]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from ..core.routes import get_crud_router
|
||||
from .models import Entity
|
||||
from .models import Entity, EntityFilters
|
||||
from .schemas import EntityCreate, EntityRead, EntityUpdate
|
||||
|
||||
router = get_crud_router(Entity, EntityCreate, EntityRead, EntityUpdate)
|
||||
|
||||
|
||||
router = get_crud_router(Entity, EntityCreate, EntityRead, EntityUpdate, EntityFilters)
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import Field
|
||||
|
||||
from .models import Entity, Institution, Individual, Corporation
|
||||
from ..core.schemas import Writer
|
||||
from ..core.schemas import Writer, Reader
|
||||
|
||||
|
||||
class EntityRead(Entity):
|
||||
class EntityRead(Entity, Reader):
|
||||
pass
|
||||
|
||||
|
||||
class EntityCreate(Writer):
|
||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||
address: str = Field(default="", title='Adresse')
|
||||
@@ -16,6 +13,5 @@ class EntityCreate(Writer):
|
||||
class Config:
|
||||
title = "Création d'un client"
|
||||
|
||||
|
||||
class EntityUpdate(EntityCreate):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user