class FilterParams(BaseModel): refid: str = None # type: ignore leadid: int = None #…
- User
class FilterParams(BaseModel): ref_id: str = None # type: ignore lead_id: int = None # type: ignore customer_name: str = None # type: ignore customer_phone_number: int = None # type: ignore customer_contact_number: int = None # type: ignore address: str = None # type: ignore actual_drawdown_amt: int = None # type: ignore case_status: str = None # type: ignore loan_amount: float = None # type: ignore property_type: Optional[str] = None # type: ignore completion_date: Optional[date] = None # type: ignore drawdown_date: Optional[date] = None # type: ignore bank_received_application: Optional[List[str]] = None # type: ignore referral_code: Optional[str] = None # type: ignore referral_submitted_date: Optional[date] = None # type: ignore deal_lost_date: Optional[date] = None # type: ignore hkmc_needed: int = None # type: ignore remarks: Optional[str] = None # type: ignore accepted_offer: str = None # type: ignore predicted_offer: str = None # type: ignore created_by: int = None # type: ignore modified_by: int = None # type: ignore
@case_router.post("/items/filtering") async def case_filtering(filter_params: FilterParams, db: Session = Depends(get_db)): try: query: Query = db.query(model_case) for column_name, column_value in filter_params.dict().items(): if column_value is not None: query = query.filter(getattr(model_case, column_name) == column_value) items = query.all() return {"items": items} except Exception as e: return "error"
is this code, i use pydantic model as filter, but it only accept one field with one value, how can i do with one field with mutil value, for example: i want the address can search the record with "address" or "string"
- Assistant
One way to handle filtering with multiple values for a single field is to use the
in_method of SQLAlchemy'sColumnobject.Here's how you can modify the existing code to include a check for this scenario:
@case_router.post("/items/filtering") async def case_filtering(filter_params: FilterParams, db: Session = Depends(get_db)): try: query: Query = db.query(model_case) for column_name, column_value in filter_params.dict().items(): if column_value is not None: if isinstance(column_value, list): query = query.filter(getattr(model_case, column_name).in_(column_value)) else: query = query.filter(getattr(model_case, column_name) == column_value) items = query.all() return {"items": items} except Exception as e: return "error"In this modified code, we check if the column value is a list. If it is, we use the
in_method to filter the query for all records that match any of the values in the list. If it's not a list, we use the existing code to filter the query for records that match the single value. - User
the jira issue of filter is updated, but maybe quite long.
If anyone dont understand, please mention me and i can explain in the call with the figma please make this sentence looks better
- Assistant
If anyone is unsure about the updated Jira issue related to filtering, please let me know and I can explain it during a call using Figma.
- User
dont need combain this 2 sentence
- Assistant
Sure, here is the revised sentence:
"If anyone requires further clarification on the updated Jira issue related to filtering, feel free to let me know. I can offer a more detailed explanation during a call through Figma."
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.