django-mongoengine-filter


Namedjango-mongoengine-filter JSON
Version 0.4.2 PyPI version JSON
download
home_pagehttps://github.com/barseghyanartur/django-mongoengine-filter
Summarydjango-mongoengine-filter is a reusable Django application inspired from django-filter for allowing mongoengine users to filter querysets dynamically.
upload_time2023-05-24 00:36:42
maintainer
docs_urlNone
authorArtur Barseghyhan
requires_python>=3.7
licenseGPL-2.0-only OR LGPL-2.1-or-later
keywords mongoengine django-filter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            =========================
django-mongoengine-filter
=========================
``django-mongoengine-filter`` is a reusable Django application for allowing
users to filter `mongoengine querysets`_ dynamically. It's very similar to
popular ``django-filter`` library and is designed to be used as a drop-in
replacement (as much as it's possible) strictly tied to ``MongoEngine``.

Full documentation on `Read the docs`_.

.. image:: https://img.shields.io/pypi/v/django-mongoengine-filter.svg
   :target: https://pypi.python.org/pypi/django-mongoengine-filter
   :alt: PyPI Version

.. image:: https://img.shields.io/pypi/pyversions/django-mongoengine-filter.svg
    :target: https://pypi.python.org/pypi/django-mongoengine-filter/
    :alt: Supported Python versions

.. image:: https://github.com/barseghyanartur/django-mongoengine-filter/workflows/test/badge.svg
   :target: https://github.com/barseghyanartur/django-mongoengine-filter/actions
   :alt: Build Status

.. image:: https://readthedocs.org/projects/django-mongoengine-filter/badge/?version=latest
    :target: http://django-mongoengine-filter.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. image:: https://img.shields.io/badge/license-GPL--2.0--only%20OR%20LGPL--2.1--or--later-blue.svg
   :target: https://github.com/barseghyanartur/django-mongoengine-filter/#License
   :alt: GPL-2.0-only OR LGPL-2.1-or-later

.. image:: https://coveralls.io/repos/github/barseghyanartur/django-mongoengine-filter/badge.svg?branch=master
    :target: https://coveralls.io/github/barseghyanartur/django-mongoengine-filter?branch=master
    :alt: Coverage

Requirements
============
* Python 3.7, 3.8, 3.9, 3.10 or 3.11.
* MongoDB 3.x, 4.x, 5.x.
* Django 2.2, 3.0, 3.1, 3.2, 4.0 or 4.1.

Installation
============
Install using pip:

.. code-block:: sh

    pip install django-mongoengine-filter

Or latest development version:

.. code-block:: sh

    pip install https://github.com/barseghyanartur/django-mongoengine-filter/archive/master.zip

Usage
=====
**Sample document**

.. code-block:: python

    from mongoengine import fields, document
    from .constants import PROFILE_TYPES, PROFILE_TYPE_FREE, GENDERS, GENDER_MALE

    class Person(document.Document):

        name = fields.StringField(
            required=True,
            max_length=255,
            default="Robot",
            verbose_name="Name"
        )
        age = fields.IntField(required=True, verbose_name="Age")
        num_fingers = fields.IntField(
            required=False,
            verbose_name="Number of fingers"
        )
        profile_type = fields.StringField(
            required=False,
            blank=False,
            null=False,
            choices=PROFILE_TYPES,
            default=PROFILE_TYPE_FREE,
        )
        gender = fields.StringField(
            required=False,
            blank=False,
            null=False,
            choices=GENDERS,
            default=GENDER_MALE
        )

        def __str__(self):
            return self.name

**Sample filter**

.. code-block:: python

    import django_mongoengine_filter

    class PersonFilter(django_mongoengine_filter.FilterSet):

        profile_type = django_mongoengine_filter.StringFilter()
        ten_fingers = django_mongoengine_filter.MethodFilter(
            action="ten_fingers_filter"
        )

        class Meta:
            model = Person
            fields = ["profile_type", "ten_fingers"]

        def ten_fingers_filter(self, queryset, name, value):
            if value == 'yes':
                return queryset.filter(num_fingers=10)
            return queryset

**Sample view**

With function-based views:

.. code-block:: python

    def person_list(request):
        filter = PersonFilter(request.GET, queryset=Person.objects)
        return render(request, "dfm_app/person_list.html", {"object_list": filter.qs})

Or class-based views:

.. code-block:: python

    from django_mongoengine_filter.views import FilterView

    class PersonListView(FilterView):

        filterset_class = PersonFilter
        template_name = "dfm_app/person_list.html"

**Sample template**

.. code-block:: html

    <ul>
    {% for obj in object_list %}
        <li>{{ obj.name }} - {{ obj.age }}</li>
    {% endfor %}
    </ul>

**Sample requests**

- GET /persons/
- GET /persons/?profile_type=free&gender=male
- GET /persons/?profile_type=free&gender=female
- GET /persons/?profile_type=member&gender=female
- GET /persons/?ten_fingers=yes

Development
===========
Testing
-------
To run tests in your working environment type:

.. code-block:: sh

    pytest -vrx

To test with all supported Python versions type:

.. code-block:: sh

    tox

Running MongoDB
---------------
The easiest way is to run it via Docker:

.. code-block:: sh

    docker pull mongo:latest
    docker run -p 27017:27017 mongo:latest

Writing documentation
---------------------
Keep the following hierarchy.

.. code-block:: text

    =====
    title
    =====

    header
    ======

    sub-header
    ----------

    sub-sub-header
    ~~~~~~~~~~~~~~

    sub-sub-sub-header
    ^^^^^^^^^^^^^^^^^^

    sub-sub-sub-sub-header
    ++++++++++++++++++++++

    sub-sub-sub-sub-sub-header
    **************************

License
=======
GPL-2.0-only OR LGPL-2.1-or-later

Support
=======
For any security issues contact me at the e-mail given in the `Author`_ section.

For overall issues, go to `GitHub <https://github.com/barseghyanartur/django-mongoengine-filter/issues>`_.

Author
======
Artur Barseghyan <artur.barseghyan@gmail.com>

.. _`mongoengine querysets`: http://mongoengine-odm.readthedocs.org/apireference.html#module-mongoengine.queryset
.. _`read the docs`: https://django-mongoengine-filter.readthedocs.org/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/barseghyanartur/django-mongoengine-filter",
    "name": "django-mongoengine-filter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "mongoengine,django-filter",
    "author": "Artur Barseghyhan",
    "author_email": "artur.barseghyan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/78/e0/8192ef56230b876751d37a22a5944822368ecd2abe6dc3520d34d9b159a0/django-mongoengine-filter-0.4.2.tar.gz",
    "platform": null,
    "description": "=========================\ndjango-mongoengine-filter\n=========================\n``django-mongoengine-filter`` is a reusable Django application for allowing\nusers to filter `mongoengine querysets`_ dynamically. It's very similar to\npopular ``django-filter`` library and is designed to be used as a drop-in\nreplacement (as much as it's possible) strictly tied to ``MongoEngine``.\n\nFull documentation on `Read the docs`_.\n\n.. image:: https://img.shields.io/pypi/v/django-mongoengine-filter.svg\n   :target: https://pypi.python.org/pypi/django-mongoengine-filter\n   :alt: PyPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/django-mongoengine-filter.svg\n    :target: https://pypi.python.org/pypi/django-mongoengine-filter/\n    :alt: Supported Python versions\n\n.. image:: https://github.com/barseghyanartur/django-mongoengine-filter/workflows/test/badge.svg\n   :target: https://github.com/barseghyanartur/django-mongoengine-filter/actions\n   :alt: Build Status\n\n.. image:: https://readthedocs.org/projects/django-mongoengine-filter/badge/?version=latest\n    :target: http://django-mongoengine-filter.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://img.shields.io/badge/license-GPL--2.0--only%20OR%20LGPL--2.1--or--later-blue.svg\n   :target: https://github.com/barseghyanartur/django-mongoengine-filter/#License\n   :alt: GPL-2.0-only OR LGPL-2.1-or-later\n\n.. image:: https://coveralls.io/repos/github/barseghyanartur/django-mongoengine-filter/badge.svg?branch=master\n    :target: https://coveralls.io/github/barseghyanartur/django-mongoengine-filter?branch=master\n    :alt: Coverage\n\nRequirements\n============\n* Python 3.7, 3.8, 3.9, 3.10 or 3.11.\n* MongoDB 3.x, 4.x, 5.x.\n* Django 2.2, 3.0, 3.1, 3.2, 4.0 or 4.1.\n\nInstallation\n============\nInstall using pip:\n\n.. code-block:: sh\n\n    pip install django-mongoengine-filter\n\nOr latest development version:\n\n.. code-block:: sh\n\n    pip install https://github.com/barseghyanartur/django-mongoengine-filter/archive/master.zip\n\nUsage\n=====\n**Sample document**\n\n.. code-block:: python\n\n    from mongoengine import fields, document\n    from .constants import PROFILE_TYPES, PROFILE_TYPE_FREE, GENDERS, GENDER_MALE\n\n    class Person(document.Document):\n\n        name = fields.StringField(\n            required=True,\n            max_length=255,\n            default=\"Robot\",\n            verbose_name=\"Name\"\n        )\n        age = fields.IntField(required=True, verbose_name=\"Age\")\n        num_fingers = fields.IntField(\n            required=False,\n            verbose_name=\"Number of fingers\"\n        )\n        profile_type = fields.StringField(\n            required=False,\n            blank=False,\n            null=False,\n            choices=PROFILE_TYPES,\n            default=PROFILE_TYPE_FREE,\n        )\n        gender = fields.StringField(\n            required=False,\n            blank=False,\n            null=False,\n            choices=GENDERS,\n            default=GENDER_MALE\n        )\n\n        def __str__(self):\n            return self.name\n\n**Sample filter**\n\n.. code-block:: python\n\n    import django_mongoengine_filter\n\n    class PersonFilter(django_mongoengine_filter.FilterSet):\n\n        profile_type = django_mongoengine_filter.StringFilter()\n        ten_fingers = django_mongoengine_filter.MethodFilter(\n            action=\"ten_fingers_filter\"\n        )\n\n        class Meta:\n            model = Person\n            fields = [\"profile_type\", \"ten_fingers\"]\n\n        def ten_fingers_filter(self, queryset, name, value):\n            if value == 'yes':\n                return queryset.filter(num_fingers=10)\n            return queryset\n\n**Sample view**\n\nWith function-based views:\n\n.. code-block:: python\n\n    def person_list(request):\n        filter = PersonFilter(request.GET, queryset=Person.objects)\n        return render(request, \"dfm_app/person_list.html\", {\"object_list\": filter.qs})\n\nOr class-based views:\n\n.. code-block:: python\n\n    from django_mongoengine_filter.views import FilterView\n\n    class PersonListView(FilterView):\n\n        filterset_class = PersonFilter\n        template_name = \"dfm_app/person_list.html\"\n\n**Sample template**\n\n.. code-block:: html\n\n    <ul>\n    {% for obj in object_list %}\n        <li>{{ obj.name }} - {{ obj.age }}</li>\n    {% endfor %}\n    </ul>\n\n**Sample requests**\n\n- GET /persons/\n- GET /persons/?profile_type=free&gender=male\n- GET /persons/?profile_type=free&gender=female\n- GET /persons/?profile_type=member&gender=female\n- GET /persons/?ten_fingers=yes\n\nDevelopment\n===========\nTesting\n-------\nTo run tests in your working environment type:\n\n.. code-block:: sh\n\n    pytest -vrx\n\nTo test with all supported Python versions type:\n\n.. code-block:: sh\n\n    tox\n\nRunning MongoDB\n---------------\nThe easiest way is to run it via Docker:\n\n.. code-block:: sh\n\n    docker pull mongo:latest\n    docker run -p 27017:27017 mongo:latest\n\nWriting documentation\n---------------------\nKeep the following hierarchy.\n\n.. code-block:: text\n\n    =====\n    title\n    =====\n\n    header\n    ======\n\n    sub-header\n    ----------\n\n    sub-sub-header\n    ~~~~~~~~~~~~~~\n\n    sub-sub-sub-header\n    ^^^^^^^^^^^^^^^^^^\n\n    sub-sub-sub-sub-header\n    ++++++++++++++++++++++\n\n    sub-sub-sub-sub-sub-header\n    **************************\n\nLicense\n=======\nGPL-2.0-only OR LGPL-2.1-or-later\n\nSupport\n=======\nFor any security issues contact me at the e-mail given in the `Author`_ section.\n\nFor overall issues, go to `GitHub <https://github.com/barseghyanartur/django-mongoengine-filter/issues>`_.\n\nAuthor\n======\nArtur Barseghyan <artur.barseghyan@gmail.com>\n\n.. _`mongoengine querysets`: http://mongoengine-odm.readthedocs.org/apireference.html#module-mongoengine.queryset\n.. _`read the docs`: https://django-mongoengine-filter.readthedocs.org/\n",
    "bugtrack_url": null,
    "license": "GPL-2.0-only OR LGPL-2.1-or-later",
    "summary": "django-mongoengine-filter is a reusable Django application inspired from django-filter for allowing mongoengine users to filter querysets dynamically.",
    "version": "0.4.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/barseghyanartur/django-mongoengine-filter/issues",
        "Changelog": "https://django-mongoengine-filter.readthedocs.io/en/latest/changelog.html",
        "Documentation": "https://django-mongoengine-filter.readthedocs.io/",
        "Homepage": "https://github.com/barseghyanartur/django-mongoengine-filter",
        "Source Code": "https://github.com/barseghyanartur/django-mongoengine-filter"
    },
    "split_keywords": [
        "mongoengine",
        "django-filter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06751082a3bb941398035c3be5993258dbc6ee335f17b0beb1be4c4dc256f1d1",
                "md5": "4502441cb36667e2befd4e366d259804",
                "sha256": "344f65c09b09475447a7903445983426b7146cb55d528be733c48cf32307b6d7"
            },
            "downloads": -1,
            "filename": "django_mongoengine_filter-0.4.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4502441cb36667e2befd4e366d259804",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 19479,
            "upload_time": "2023-05-24T00:36:39",
            "upload_time_iso_8601": "2023-05-24T00:36:39.999482Z",
            "url": "https://files.pythonhosted.org/packages/06/75/1082a3bb941398035c3be5993258dbc6ee335f17b0beb1be4c4dc256f1d1/django_mongoengine_filter-0.4.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78e08192ef56230b876751d37a22a5944822368ecd2abe6dc3520d34d9b159a0",
                "md5": "b9deb1acdc2b0cde3886be0865c6529c",
                "sha256": "597b9807e8210c0eb70419ac8d28993d30b3bc7c56cd796bebd4a6cc09ac33e4"
            },
            "downloads": -1,
            "filename": "django-mongoengine-filter-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b9deb1acdc2b0cde3886be0865c6529c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 37090,
            "upload_time": "2023-05-24T00:36:42",
            "upload_time_iso_8601": "2023-05-24T00:36:42.510176Z",
            "url": "https://files.pythonhosted.org/packages/78/e0/8192ef56230b876751d37a22a5944822368ecd2abe6dc3520d34d9b159a0/django-mongoengine-filter-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-24 00:36:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "barseghyanartur",
    "github_project": "django-mongoengine-filter",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "django-mongoengine-filter"
}
        
Elapsed time: 1.05451s