django-ufilter


Namedjango-ufilter JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/Qu4tro/django-ufilter
Summarydjango-ufilter provides a safe way to filter data.
upload_time2023-05-04 22:45:27
maintainerXavier Francisco
docs_urlNone
authorMiroslav Shubernetskiy
requires_python>=3.7,<4.0
licenseMIT
keywords django django-rest-framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =================
Django UFilter
=================

.. image:: https://badge.fury.io/py/django-ufilter.svg
   :target: http://badge.fury.io/py/django-ufilter
.. image:: https://readthedocs.org/projects/django-ufilter/badge/?version=latest
   :target: http://django-ufilter.readthedocs.io/en/latest/?badge=latest

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

This project was forked from https://github.com/miki725/django-url-filter, due to the lack of maintenance in the original one.

* Free software: MIT license
* GitHub: https://github.com/Qu4tro/django-ufilter/
* Documentation: http://django-ufilter.readthedocs.io/

Overview
--------

The main goal of Django UFilter 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 UFilter 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 2.7, 3.x, pypy or pypy3
* Django 1.8+ (there are plans to support older Django versions)
* 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 django-ufilter

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

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

::

  from django_ufilter.integrations.drf import DRFFilterBackend


  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 django_ufilter.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 UFilter 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

Available lookups:

* contains: Match when string contains given substring.
* day: Match by day of the month.
* endswith: Match when string ends with given substring.
* exact: Match exactly the value as is.
* gt: Match when value is greater then given value.
* gte: Match when value is greater or equal then given value.
* hour: Match by the hour (24 hour) value of the timestamp.
* icontains: Case insensitive match when string contains given substring.
* iendswith: Case insensitive match when string ends with given substring.
* iexact: Case insensitive match exactly the value as is.
* iin: Case insensitive match when value is any of given comma separated values.
* in: Match when value is any of given comma separated values.
* iregex: Case insensitive match string by regex pattern.
* isnull: Match when value is NULL.
* istartswith: Case insensitive match when string starts with given substring.
* lt: Match when value is less then given value.
* lte: Match when value is less or equal then given value.
* minute: Match by the minute value of the timestamp.
* month: Match by the month value of the timestamp.
* range: Match when value is within comma separated range.
* regex: Match string by regex pattern.
* second: Match by the second value of the timestamp.
* startswith: Match when string starts with given substring.
* week_day: Match by week day (1-Sunday to 7-Saturday) of the timestamp.
* year: Match by the year value of the timestamp.
* len: Match the length of a given ArrayField

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. plain Python 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": "https://github.com/Qu4tro/django-ufilter",
    "name": "django-ufilter",
    "maintainer": "Xavier Francisco",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "xavier.n.francisco@gmail.com",
    "keywords": "django,django-rest-framework",
    "author": "Miroslav Shubernetskiy",
    "author_email": "miroslav@miki725.com",
    "download_url": "https://files.pythonhosted.org/packages/99/b9/9fe54ac22dc74a61f06942035649ee5f35ac820cfb002085eb170982e69f/django_ufilter-0.4.3.tar.gz",
    "platform": null,
    "description": "=================\nDjango UFilter\n=================\n\n.. image:: https://badge.fury.io/py/django-ufilter.svg\n   :target: http://badge.fury.io/py/django-ufilter\n.. image:: https://readthedocs.org/projects/django-ufilter/badge/?version=latest\n   :target: http://django-ufilter.readthedocs.io/en/latest/?badge=latest\n\nDjango UFilter provides a safe way to filter data via human-friendly URLs.\n\nThis project was forked from https://github.com/miki725/django-url-filter, due to the lack of maintenance in the original one.\n\n* Free software: MIT license\n* GitHub: https://github.com/Qu4tro/django-ufilter/\n* Documentation: http://django-ufilter.readthedocs.io/\n\nOverview\n--------\n\nThe main goal of Django UFilter 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 UFilter 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 2.7, 3.x, pypy or pypy3\n* Django 1.8+ (there are plans to support older Django versions)\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 django-ufilter\n\nUsage Example\n-------------\n\nTo make example short, it demonstrates Django UFilter integration\nwith Django REST Framework but it can be used without DRF (see below).\n\n::\n\n  from django_ufilter.integrations.drf import DRFFilterBackend\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 django_ufilter.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 UFilter features.\nSome possibilities:\n\n* get user with id 5\n\n    example.com/users/?id=5\n\n* get user with id either 5, 10 or 15\n\n    example.com/users/?id__in=5,10,15\n\n* get user with id between 5 and 10\n\n    example.com/users/?id__range=5,10\n\n* get user with username \"foo\"\n\n    example.com/users/?username=foo\n\n* get user with username containing case insensitive \"foo\"\n\n    example.com/users/?username__icontains=foo\n\n* get user where username does NOT contain \"foo\"\n\n    example.com/users/?username__icontains!=foo\n\n* get user who joined in 2015 as per user profile\n\n    example.com/users/?profile__joined__year=2015\n\n* get user who joined in between 2010 and 2015 as per user profile\n\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\n    example.com/users/?profile__joined__gt=2010-01-01\n\nAvailable lookups:\n\n* contains: Match when string contains given substring.\n* day: Match by day of the month.\n* endswith: Match when string ends with given substring.\n* exact: Match exactly the value as is.\n* gt: Match when value is greater then given value.\n* gte: Match when value is greater or equal then given value.\n* hour: Match by the hour (24 hour) value of the timestamp.\n* icontains: Case insensitive match when string contains given substring.\n* iendswith: Case insensitive match when string ends with given substring.\n* iexact: Case insensitive match exactly the value as is.\n* iin: Case insensitive match when value is any of given comma separated values.\n* in: Match when value is any of given comma separated values.\n* iregex: Case insensitive match string by regex pattern.\n* isnull: Match when value is NULL.\n* istartswith: Case insensitive match when string starts with given substring.\n* lt: Match when value is less then given value.\n* lte: Match when value is less or equal then given value.\n* minute: Match by the minute value of the timestamp.\n* month: Match by the month value of the timestamp.\n* range: Match when value is within comma separated range.\n* regex: Match string by regex pattern.\n* second: Match by the second value of the timestamp.\n* startswith: Match when string starts with given substring.\n* week_day: Match by week day (1-Sunday to 7-Saturday) of the timestamp.\n* year: Match by the year value of the timestamp.\n* len: Match the length of a given ArrayField\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. plain Python 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-ufilter provides a safe way to filter data.",
    "version": "0.4.3",
    "project_urls": {
        "Homepage": "https://github.com/Qu4tro/django-ufilter",
        "Repository": "https://github.com/Qu4tro/django-ufilter"
    },
    "split_keywords": [
        "django",
        "django-rest-framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c22574c2c5704e648fb9df87ba3d16c4e862a956475d49b184578734120e0db",
                "md5": "ca849f2b440e0fca62c9b3574531e0e3",
                "sha256": "f29a9fdc5dfc57de4d158d9b5f2de3ebcd2069d10afff1b8c72b7029d872efe4"
            },
            "downloads": -1,
            "filename": "django_ufilter-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ca849f2b440e0fca62c9b3574531e0e3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 31840,
            "upload_time": "2023-05-04T22:45:24",
            "upload_time_iso_8601": "2023-05-04T22:45:24.835630Z",
            "url": "https://files.pythonhosted.org/packages/9c/22/574c2c5704e648fb9df87ba3d16c4e862a956475d49b184578734120e0db/django_ufilter-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99b99fe54ac22dc74a61f06942035649ee5f35ac820cfb002085eb170982e69f",
                "md5": "1b297cdf59cc901ebc88adae42754aa7",
                "sha256": "cc5077f65e1c42e9c498c9f04f440c3b542e14ea94443a14d920ed248f6efd3d"
            },
            "downloads": -1,
            "filename": "django_ufilter-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1b297cdf59cc901ebc88adae42754aa7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 39589,
            "upload_time": "2023-05-04T22:45:27",
            "upload_time_iso_8601": "2023-05-04T22:45:27.610191Z",
            "url": "https://files.pythonhosted.org/packages/99/b9/9fe54ac22dc74a61f06942035649ee5f35ac820cfb002085eb170982e69f/django_ufilter-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-04 22:45:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Qu4tro",
    "github_project": "django-ufilter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-ufilter"
}
        
Elapsed time: 0.07929s