add and/or/not to filtergroups, add left and right shift to operators, add some tests, add *args to other functions that read data and use filter
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import Optional
|
||||
from typing import Any, Dict, Optional, Set, Type, Union, cast
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
@ -8,6 +8,7 @@ from fastapi import FastAPI
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
import ormar
|
||||
from ormar.queryset.utils import translate_list_to_dict
|
||||
from tests.settings import DATABASE_URL
|
||||
|
||||
app = FastAPI()
|
||||
@ -84,6 +85,24 @@ to_exclude_ormar = {
|
||||
}
|
||||
|
||||
|
||||
def auto_exclude_id_field(to_exclude: Any) -> Union[Dict, Set]:
|
||||
if isinstance(to_exclude, dict):
|
||||
for key in to_exclude.keys():
|
||||
to_exclude[key] = auto_exclude_id_field(to_exclude[key])
|
||||
to_exclude["id"] = Ellipsis
|
||||
return to_exclude
|
||||
else:
|
||||
return {"id"}
|
||||
|
||||
|
||||
def generate_exclude_for_ids(model: Type[ormar.Model]) -> Dict:
|
||||
to_exclude_base = translate_list_to_dict(model._iterate_related_models())
|
||||
return cast(Dict, auto_exclude_id_field(to_exclude=to_exclude_base))
|
||||
|
||||
|
||||
to_exclude_auto = generate_exclude_for_ids(model=Department)
|
||||
|
||||
|
||||
@app.post("/departments/", response_model=Department)
|
||||
async def create_department(department: Department):
|
||||
await department.save_related(follow=True, save_all=True)
|
||||
|
||||
Reference in New Issue
Block a user