Skip to main content

django drf query filter

Project description

django-orm-filter

django drf query filter

Install

pip install django-orm-filter

Use

from orm_filter.filter import OrmFilter, FQ

class UserViewSet(viewsets.ModelViewSet):
      filter_backends = [OrmFilter,]

      # 设置需要匹配的查询参数
      orm_fields = [
          # 基本的 and 查询   
          # date_joined__lt=2021-12-09&date_joined__gt=2021-12-1
          FQ(r'date_joined__(lt|gt)$'),

          # 获取查询参数数组
          # date_joined__range=2021-12-10&date_joined__range=2021-12-12'
          FQ(r'date_joined__range$', many=True),

          # 对查询的key和value进行转换
          # ids=[1,2,10]
          FQ(r'ids$', fv=json.loads, error_text='ids 必须是json数组', repl='id__in'),

          # 正则表达式查询
          # email__regex=gmail.com$
          FQ(r'email__regex$'),

          # or 查询
          # is_staff=false&email__iendswith=qq.com
          # filter( Q(is_staff=False) | Q(email__iendswith=qq.com) )
          FQ(r'email__iendswith$', cond='or'),
          FQ(r'is_staff$', json.loads, cond='or'),

          # not 查询
          # email__not=ajanuw@qq.com
          # ~Q(email='ajanuw@qq.com')
          FQ(r"email__not$", is_not=True, repl='email')
      ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-orm-filter-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

django_orm_filter-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file django-orm-filter-0.1.0.tar.gz.

File metadata

  • Download URL: django-orm-filter-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django-orm-filter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05f8e72b721580f3cb679d2c81194700995059716db1fd9c666d6f79f58daca9
MD5 e8778f4cf2e4466aaa022a36cb061d18
BLAKE2b-256 8ba59fbd5a4fc0c5aa996055da2f58dfe26eee5a9cacafd6d95024dc4d4e9f30

See more details on using hashes here.

Provenance

File details

Details for the file django_orm_filter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_orm_filter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django_orm_filter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fe2a2c3fc7c05009b58fdc1dbed8a9a0067055a9bf20d2bd4bbf63e6feb16e0
MD5 4f8b275a73b7e7b6495f2de0900a10c0
BLAKE2b-256 facc50fdeb55b2ed5f89baf0b5b1a33be19f335ad276f65e135e0eed3fc4ed1f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page