Skip to content

docs - update the example ColumnFilter#949

Merged
aminalaee merged 3 commits intoaminalaee:mainfrom
proby-actvo:update-ColumnFilter-docs
Oct 2, 2025
Merged

docs - update the example ColumnFilter#949
aminalaee merged 3 commits intoaminalaee:mainfrom
proby-actvo:update-ColumnFilter-docs

Conversation

@proby-actvo
Copy link
Contributor

The lookups method requires a fourth, run_query, argument.
The get_filtered_query method requires a fourth, model, argument.

Also updated the docs, a minor clarification, that the above two are methods not fields.

It also looks like my editor removed some extra whitespace on save, I hope that's ok.

I'm also willing, if there's interest, to update the column filter code to add a BaseFilter(ABC) base class for all filters. Something to help enforce API consistency. Roughly:

class BaseFilter(ABC):
    """
    Base class for all filters.

    All column filters should inherit this class and implement the required methods.
    """
    @abstractmethod
    def lookups(self, request: Request, model: Any, run_query: Callable[[Select], Any]) -> List[Tuple[str, str]]:
        raise NotImplementedError

    @abstractmethod
    def get_filtered_query(self, query: Select, value: Any, model: Any) -> Select:
        raise NotImplementedError

The `lookups` method requires a fourth, `run_query`, argument.
The `get_filtered_query` method requires a fourth, `model`, argument.

Also updated the docs, a minor clarification, that the above two are
methods not fields.
A ColumnFilter is a class that defines a filter for a column. A few standard filters are implemented in `sqladmin.filters` module. Here is an example of a generic ColumnFilter. Note that the fields `title`, `parameter_name`, `lookups` and `get_filtered_query` are required.

A ColumnFilter is a class that defines a filter for a column. A few standard filters are implemented in `sqladmin.filters` module. Here is an example of a generic ColumnFilter. Note that the fields `title` & `parameter_name` and the methods `lookups` & `get_filtered_query` are required.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @proby-actvo , Thanks for your contribution. I think this version can be more clear:

Suggested change
A ColumnFilter is a class that defines a filter for a column. A few standard filters are implemented in `sqladmin.filters` module. Here is an example of a generic ColumnFilter. Note that the fields `title` & `parameter_name` and the methods `lookups` & `get_filtered_query` are required.
A ColumnFilter is a class that defines a filter for a column. A few standard filters are implemented in `sqladmin.filters` module. Here is an example of a generic ColumnFilter. Note that the fields `title` and `parameter_name`, and the methods `lookups` and `get_filtered_query` are all required in a filter class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @birddevelper -- good suggestions, much appreciated. I've adopted your suggestions.

* added "the" before "`sqladmin.filters` module"
* changed "Here" to "Below"
* changed "&" to "and"
* added comma to clearly separate the fields from the methods
* further clarify the requirement is in a filter class
broke the lines before 100 chars as that seems to be the most common breaking point in this file
@aminalaee aminalaee changed the title docs - update the example ColumnFilter to align with the implementation docs - update the example ColumnFilter Oct 2, 2025
@aminalaee aminalaee merged commit 739e179 into aminalaee:main Oct 2, 2025
5 checks passed
@proby-actvo proby-actvo deleted the update-ColumnFilter-docs branch October 6, 2025 21:26
@aminalaee aminalaee mentioned this pull request Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants