How to access request in Pydantic model #2491
Unanswered
Ibrahim-abdelaziz
asked this question in
Question
Replies: 1 comment
-
In future please try to format the markdown in your questions to make them easier to read. By default there's no way to do this, see #1549. For now you could use But in general you should avoid referencing the request within validators, since your models should be de-coupled from the request. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello all,
I'd like to ask you about somepoints as below:-
1- how to access to request in pydantic model in fastapi like serializer in django by (context.get('request'))
2- how to return extra attribute to response model in endpoint like this
@case_router.get("/case", response_model=CaseOut)
async def get_case(db: Session = Depends(get_db), pagination: Pagination = Depends(), auth: HeaderAuth = Depends()):
is_favourite = false
qs = query(Favourite).filter_by(practitioner_id=auth.id).first()
if qs:
is_favourite = true # how to return this attribute with response_model
query = crud.case.get_multi(db_session=db, is_deleted=False)
return pagination.paginate(query)
Could you please help me to know that, thanks.
Beta Was this translation helpful? Give feedback.
All reactions