dj-url-filter


Namedj-url-filter JSON
Version 0.4.4 PyPI version JSON
download
home_page
SummaryDjango URL Filter provides a safe way to filter data via human-friendly URLs.
upload_time2023-01-12 08:30:27
maintainer
docs_urlNone
authorHat Dao
requires_python>=3.9,<4.0
licenseMIT
keywords django url-filter drf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =================
Django URL Filter
=================

.. image:: https://badge.fury.io/py/dj-url-filter.svg
   :target: http://badge.fury.io/py/dj-url-filter
.. image:: https://readthedocs.org/projects/django-url-filter/badge/?version=latest
   :target: http://django-url-filter.readthedocs.io/en/latest/?badge=latest
.. image:: https://codecov.io/gh/enjoy2000/django-url-filter/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/enjoy2000/django-url-filter

Django URL Filter provides a safe way to filter data via human-friendly URLs.

* Free software: MIT license
* GitHub: https://github.com/enjoy2000/django-url-filter
* Documentation: http://django-url-filter.readthedocs.io/

Notes
-----
This is a forked version of https://github.com//miki725/django-url-filter to add Django 4 support and my other projects.

Overview
--------

The main goal of Django URL Filter is to provide an easy URL interface
for filtering data. It allows the user to safely filter by model
attributes and also allows to specify the lookup type for each filter
(very much like Django's filtering system in ORM).

For example the following will retrieve all items where the id is
``5`` and title contains ``"foo"``::

    example.com/listview/?id=5&title__contains=foo

In addition to basic lookup types, Django URL Filter allows to
use more sophisticated lookups such as ``in`` or ``year``.
For example::

    example.com/listview/?id__in=1,2,3&created__year=2013

Requirements
------------

* Python 3.9+
* Django 3.4+
* Django REST Framework 2 or 3 (only if you want to use DRF integration)

Installing
----------

Easiest way to install this library is by using ``pip``::

    $ pip install dj-url-filter

Usage Example
-------------

To make example short, it demonstrates Django URL Filter integration
with Django REST Framework but it can be used without DRF (see below).

::

  from url_filter.integrations.drf import DjangoFilterBackend


  class UserViewSet(ModelViewSet):
      queryset = User.objects.all()
      serializer_class = UserSerializer
      filter_backends = [DjangoFilterBackend]
      filter_fields = ['username', 'email']

Alternatively filterset can be manually created and used directly
to filter querysets::

  from django.http import QueryDict
  from url_filter.filtersets import ModelFilterSet


  class UserFilterSet(ModelFilterSet):
      class Meta(object):
          model = User

  query = QueryDict('email__contains=gmail&joined__gt=2015-01-01')
  fs = UserFilterSet(data=query, queryset=User.objects.all())
  filtered_users = fs.filter()

Above will automatically allow the use of all of the Django URL Filter features.
Some possibilities::

    # get user with id 5
    example.com/users/?id=5

    # get user with id either 5, 10 or 15
    example.com/users/?id__in=5,10,15

    # get user with id between 5 and 10
    example.com/users/?id__range=5,10

    # get user with username "foo"
    example.com/users/?username=foo

    # get user with username containing case insensitive "foo"
    example.com/users/?username__icontains=foo

    # get user where username does NOT contain "foo"
    example.com/users/?username__icontains!=foo

    # get user who joined in 2015 as per user profile
    example.com/users/?profile__joined__year=2015

    # get user who joined in between 2010 and 2015 as per user profile
    example.com/users/?profile__joined__range=2010-01-01,2015-12-31

    # get user who joined in after 2010 as per user profile
    example.com/users/?profile__joined__gt=2010-01-01

Features
--------

* **Human-friendly URLs**

  Filter querystring format looks
  very similar to syntax for filtering in Django ORM.
  Even negated filters are supported! Some examples::

    example.com/users/?email__contains=gmail&joined__gt=2015-01-01
    example.com/users/?email__contains!=gmail  # note !

* **Related models**

  Support related fields so that filtering can be applied to related
  models. For example::

    example.com/users/?profile__nickname=foo

* **Decoupled filtering**

  How URLs are parsed and how data is filtered is decoupled.
  This allows the actual filtering logic to be decoupled from Django
  hence filtering is possible not only with Django ORM QuerySet but
  any set of data can be filtered (e.g. SQLAlchemy query objects)
  assuming corresponding filtering backend is implemented.

* **Usage-agnostic**

  This library decouples filtering from any particular usage-pattern.
  It implements all the basic building blocks for creating
  filtersets but it does not assume how they will be used.
  To make the library easy to use, it ships with some integrations
  with common usage patterns like integration with Django REST Framework.
  This means that its easy to use in custom applications with custom
  requirements (which is probably most of the time!)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "dj-url-filter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "django,url-filter,drf",
    "author": "Hat Dao",
    "author_email": "enjoy3013@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/01/f4/b2e3f84e8e973df4f58061f6f227f246e0d5be590aaf7f2cf5ff9ca2ba0f/dj_url_filter-0.4.4.tar.gz",
    "platform": null,
    "description": "=================\nDjango URL Filter\n=================\n\n.. image:: https://badge.fury.io/py/dj-url-filter.svg\n   :target: http://badge.fury.io/py/dj-url-filter\n.. image:: https://readthedocs.org/projects/django-url-filter/badge/?version=latest\n   :target: http://django-url-filter.readthedocs.io/en/latest/?badge=latest\n.. image:: https://codecov.io/gh/enjoy2000/django-url-filter/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/enjoy2000/django-url-filter\n\nDjango URL Filter provides a safe way to filter data via human-friendly URLs.\n\n* Free software: MIT license\n* GitHub: https://github.com/enjoy2000/django-url-filter\n* Documentation: http://django-url-filter.readthedocs.io/\n\nNotes\n-----\nThis is a forked version of https://github.com//miki725/django-url-filter to add Django 4 support and my other projects.\n\nOverview\n--------\n\nThe main goal of Django URL Filter is to provide an easy URL interface\nfor filtering data. It allows the user to safely filter by model\nattributes and also allows to specify the lookup type for each filter\n(very much like Django's filtering system in ORM).\n\nFor example the following will retrieve all items where the id is\n``5`` and title contains ``\"foo\"``::\n\n    example.com/listview/?id=5&title__contains=foo\n\nIn addition to basic lookup types, Django URL Filter allows to\nuse more sophisticated lookups such as ``in`` or ``year``.\nFor example::\n\n    example.com/listview/?id__in=1,2,3&created__year=2013\n\nRequirements\n------------\n\n* Python 3.9+\n* Django 3.4+\n* Django REST Framework 2 or 3 (only if you want to use DRF integration)\n\nInstalling\n----------\n\nEasiest way to install this library is by using ``pip``::\n\n    $ pip install dj-url-filter\n\nUsage Example\n-------------\n\nTo make example short, it demonstrates Django URL Filter integration\nwith Django REST Framework but it can be used without DRF (see below).\n\n::\n\n  from url_filter.integrations.drf import DjangoFilterBackend\n\n\n  class UserViewSet(ModelViewSet):\n      queryset = User.objects.all()\n      serializer_class = UserSerializer\n      filter_backends = [DjangoFilterBackend]\n      filter_fields = ['username', 'email']\n\nAlternatively filterset can be manually created and used directly\nto filter querysets::\n\n  from django.http import QueryDict\n  from url_filter.filtersets import ModelFilterSet\n\n\n  class UserFilterSet(ModelFilterSet):\n      class Meta(object):\n          model = User\n\n  query = QueryDict('email__contains=gmail&joined__gt=2015-01-01')\n  fs = UserFilterSet(data=query, queryset=User.objects.all())\n  filtered_users = fs.filter()\n\nAbove will automatically allow the use of all of the Django URL Filter features.\nSome possibilities::\n\n    # get user with id 5\n    example.com/users/?id=5\n\n    # get user with id either 5, 10 or 15\n    example.com/users/?id__in=5,10,15\n\n    # get user with id between 5 and 10\n    example.com/users/?id__range=5,10\n\n    # get user with username \"foo\"\n    example.com/users/?username=foo\n\n    # get user with username containing case insensitive \"foo\"\n    example.com/users/?username__icontains=foo\n\n    # get user where username does NOT contain \"foo\"\n    example.com/users/?username__icontains!=foo\n\n    # get user who joined in 2015 as per user profile\n    example.com/users/?profile__joined__year=2015\n\n    # get user who joined in between 2010 and 2015 as per user profile\n    example.com/users/?profile__joined__range=2010-01-01,2015-12-31\n\n    # get user who joined in after 2010 as per user profile\n    example.com/users/?profile__joined__gt=2010-01-01\n\nFeatures\n--------\n\n* **Human-friendly URLs**\n\n  Filter querystring format looks\n  very similar to syntax for filtering in Django ORM.\n  Even negated filters are supported! Some examples::\n\n    example.com/users/?email__contains=gmail&joined__gt=2015-01-01\n    example.com/users/?email__contains!=gmail  # note !\n\n* **Related models**\n\n  Support related fields so that filtering can be applied to related\n  models. For example::\n\n    example.com/users/?profile__nickname=foo\n\n* **Decoupled filtering**\n\n  How URLs are parsed and how data is filtered is decoupled.\n  This allows the actual filtering logic to be decoupled from Django\n  hence filtering is possible not only with Django ORM QuerySet but\n  any set of data can be filtered (e.g. SQLAlchemy query objects)\n  assuming corresponding filtering backend is implemented.\n\n* **Usage-agnostic**\n\n  This library decouples filtering from any particular usage-pattern.\n  It implements all the basic building blocks for creating\n  filtersets but it does not assume how they will be used.\n  To make the library easy to use, it ships with some integrations\n  with common usage patterns like integration with Django REST Framework.\n  This means that its easy to use in custom applications with custom\n  requirements (which is probably most of the time!)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django URL Filter provides a safe way to filter data via human-friendly URLs.",
    "version": "0.4.4",
    "split_keywords": [
        "django",
        "url-filter",
        "drf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1431a0bd12b58a3f3517d2c7a78c3b8f4e5e57de84b50448fd39ddc20098fe1f",
                "md5": "2e729c66883c111b1fbf70b128ef47ba",
                "sha256": "43773a8a9c169e0b5539b916cb55693695a20c13ad0aeaa7a8ffd7f964ebd2a9"
            },
            "downloads": -1,
            "filename": "dj_url_filter-0.4.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2e729c66883c111b1fbf70b128ef47ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 36365,
            "upload_time": "2023-01-12T08:30:26",
            "upload_time_iso_8601": "2023-01-12T08:30:26.151849Z",
            "url": "https://files.pythonhosted.org/packages/14/31/a0bd12b58a3f3517d2c7a78c3b8f4e5e57de84b50448fd39ddc20098fe1f/dj_url_filter-0.4.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01f4b2e3f84e8e973df4f58061f6f227f246e0d5be590aaf7f2cf5ff9ca2ba0f",
                "md5": "7611677054e4e12b54a5b9d85fbeb90b",
                "sha256": "80cb8d71cbc296e10475b41d58ab8e172e9e8370ae08e5737bf68b9d7061a07e"
            },
            "downloads": -1,
            "filename": "dj_url_filter-0.4.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7611677054e4e12b54a5b9d85fbeb90b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 29503,
            "upload_time": "2023-01-12T08:30:27",
            "upload_time_iso_8601": "2023-01-12T08:30:27.916228Z",
            "url": "https://files.pythonhosted.org/packages/01/f4/b2e3f84e8e973df4f58061f6f227f246e0d5be590aaf7f2cf5ff9ca2ba0f/dj_url_filter-0.4.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-12 08:30:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "dj-url-filter"
}
        
Elapsed time: 0.06240s