Compare commits

..

2 Commits
1.2.2 ... 1.2.3

Author SHA1 Message Date
creyD
fa7a1c8a61 Adjusted files for isort & autopep 2024-05-13 09:22:06 +00:00
5a7e1776db fix: Added option to specify lookup_column for get_object_or_404 2024-05-13 11:21:25 +02:00
2 changed files with 9 additions and 3 deletions

View File

@@ -2,7 +2,11 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 1.2.X ## 1.2.3
- Added option to specify lookup_column for get_object_or_404
## 1.2.2
- Added order_by method - Added order_by method

View File

@@ -10,8 +10,10 @@ from .models.base import Base
T = TypeVar("T", bound=Base) T = TypeVar("T", bound=Base)
def get_object_or_404(db_class: Type[T], id: UUID | str, db: Session, expunge: bool = False) -> T: def get_object_or_404(
obj = db.query(db_class).filter(db_class.id == id).one_or_none() db_class: Type[T], id: UUID | str, db: Session, expunge: bool = False, lookup_column: str = "id"
) -> T:
obj = db.query(db_class).filter(getattr(db_class, lookup_column) == id).one_or_none()
if obj is None: if obj is None:
raise HTTPException(status_code=404, detail="The object does not exist.") raise HTTPException(status_code=404, detail="The object does not exist.")
if expunge: if expunge: