Skip to content

Instantly share code, notes, and snippets.

@Dimitrionian
Created April 11, 2023 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimitrionian/fff33850d0d43a4b2e410d65830d8ae2 to your computer and use it in GitHub Desktop.
Save Dimitrionian/fff33850d0d43a4b2e410d65830d8ae2 to your computer and use it in GitHub Desktop.
Generalized queryset filtration by different fields
@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