fastapi-filter icon indicating copy to clipboard operation
fastapi-filter copied to clipboard

Custom field name

Open murtazox04 opened this issue 1 year ago • 1 comments

Hey hello!

class CompanyFilter(Filter):
    id: Optional[str] = Field(None)
    region: Optional[str] = None
    district: Optional[str] = None
    categories: CompanyCategoryFilter = FilterDepends(CompanyCategoryFilter)

    class Constants(Filter.Constants):
        model = Company

class MyReviewFilter(Filter):
    id: Optional[str] = None
    company_filter: CompanyFilter = FilterDepends(with_prefix("company", CompanyFilter))
    rating: Optional[int] = None

here the filter generate filed name -> company__id, but I need the name only company, how can fix it?

If I use pydantic alias the field only change schema name, but the api param dont changed. Pls help me!

murtazox04 avatar Aug 02 '24 05:08 murtazox04

Sorry. I dont add by_alias in company_filter: CompanyFilter = FilterDepends(with_prefix("company", CompanyFilter))

It worked!!!

murtazox04 avatar Aug 02 '24 05:08 murtazox04

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 02 '24 02:10 github-actions[bot]