Bank Services tested and completed
This commit is contained in:
@@ -216,6 +216,7 @@ class CRUDModel:
|
||||
cls,
|
||||
db: Session,
|
||||
exclude_args: Optional[list[InstrumentedAttribute]] = None,
|
||||
include_args: Optional[list[InstrumentedAttribute]] = None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
@@ -224,6 +225,7 @@ class CRUDModel:
|
||||
Args:
|
||||
db: Database session
|
||||
exclude_args: Keys to exclude from search
|
||||
include_args: Keys to specifically include in search (if provided, only these will be used)
|
||||
**kwargs: Search/creation criteria
|
||||
|
||||
Returns:
|
||||
@@ -238,10 +240,18 @@ class CRUDModel:
|
||||
|
||||
exclude_args = exclude_args or []
|
||||
exclude_args = [exclude_arg.key for exclude_arg in exclude_args]
|
||||
|
||||
|
||||
include_args = include_args or []
|
||||
include_args = [include_arg.key for include_arg in include_args]
|
||||
|
||||
# If include_args is provided, only use those fields for matching
|
||||
# Otherwise, use all fields except those in exclude_args
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(cls, key) and key not in exclude_args:
|
||||
query = query.filter(getattr(cls, key) == value)
|
||||
if hasattr(cls, key):
|
||||
if include_args and key in include_args:
|
||||
query = query.filter(getattr(cls, key) == value)
|
||||
elif not include_args and key not in exclude_args:
|
||||
query = query.filter(getattr(cls, key) == value)
|
||||
|
||||
already_record = query.first()
|
||||
if already_record: # Handle existing record
|
||||
|
||||
Reference in New Issue
Block a user