Created
April 11, 2023 06:59
-
-
Save Dimitrionian/fff33850d0d43a4b2e410d65830d8ae2 to your computer and use it in GitHub Desktop.
Generalized queryset filtration by different fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def filter_by_field(cls, filter_str: str, field: str, items: QuerySet) -> QuerySet: | |
"""Filter page items by different fields""" | |
criterion = { | |
f'{field}__contains': filter_str | |
} | |
return items.filter(**criterion) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment