Mochinov

Untitled

Feb 21st, 2022 (edited)
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1.  
  2.         @classmethod
  3.         def social_media_type(cls, field_name: str, query_string: str, query_set: QuerySet) -> QuerySet:
  4.             """Фильтр по типу социальной сети."""
  5.             social_media_type_field = split_query(query_string)
  6.             query_set = query_set.filter(
  7.                 Q(social_media__social_media_type=social_media_type_field)
  8.             )
  9.  
  10.             return query_set
  11.  
  12.         @classmethod
  13.         def social_media_type_link(cls, field_name: str, query_string: str, query_set: QuerySet) -> QuerySet:
  14.             """Фильтр по ссылки социальной сети."""
  15.  
  16.             filter_link_field = split_query(query_string)
  17.             query_set = query_set.filter(
  18.                 Q(
  19.                     Q(reduce(lambda x, y: x | y,
  20.                         [Q(**{'social_media__link': par}) for par in filter_link_field]
  21.                     ))
  22.                 )
  23.             )
  24.             return query_set
  25.  
  26.  
  27.  
  28.     FIELDS_FILTERS = [
  29.  
  30.         GenericApiView.get_filter(
  31.             filter_name='social_media__link_field', field_name='link', filer_method=Filters.social_media_type_link
  32.         ),
  33.  
  34.         GenericApiView.get_filter(
  35.             filter_name='social_media__social_media_type_field', field_name='social_media_type',         
  36.             filer_method=Filters.social_media_type
  37.         ),
  38.            ........
Add Comment
Please, Sign In to add comment