django-mongoengine-filter is a reusable Django application inspired from django-filter for allowing mongoengine users to filter querysets dynamically.
Project description
Django Filter MonogoEngine
django-mongoengine-filter is a reusable Django application for allowing users to filter mongoengine querysets dynamically.
Full documentation on read the docs.
Requirements
Python 3.5+
Django 2.1+
Installation
Install using pip:
pip install django-mongoengine-filter
Or latest development version from repository:
pip install https://github.com/barseghyanartur/django-mongoengine-filter/archive/master.zip
Usage
Sample document
from mongoengine import fields, document
from .constants import PROFILE_TYPES, PROFILE_TYPE_FREE, GENDERS, GENDER_MALE
__all__ = ("Person",)
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
import django_filters_mongoengine
class PersonFilter(django_filters_mongoengine.FilterSet):
profile_type = django_filters_mongoengine.StringFilter()
ten_fingers = django_filters_mongoengine.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
def person_list(request):
filter = PersonFilter(request.GET, queryset=Person.objects())
return render(request, "dfm_app/person_list.html", {"objects": filter.qs})
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
Read more
Development
Testing
To run tests in your working environment type:
./runtests.py
To test with all supported Python versions type:
tox
Running MongoDB
The easiest way is to run it via Docker:
docker pull mongo:latest
docker run -p 27017:27017 mongo:latest
Writing documentation
Keep the following hierarchy.
=====
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/LGPL 2.1
Support
For any issues contact me at the e-mail given in the Author section.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-mongoengine-filter-0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e24e5cb0d067b6a25534185656361d4269ec51640758c8994fec8c8e1cd238aa |
|
MD5 | 30de65da15cbdec4024791a2fc223359 |
|
BLAKE2b-256 | fc6b2385f4a8d7c5eef21b36477dd1542a7620a69a3ad6968afcc7f1e86e1172 |
Hashes for django_mongoengine_filter-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14c4b5b837e815a235e409b5adc43817dc3e60e75852b4f88f10409094b35702 |
|
MD5 | 72f0903aa328379548d02870b5f0d32a |
|
BLAKE2b-256 | eee6819b81ed2b5483b4e0989b4a76bb3b3c12a3a79d6702b6b770dfeea0557a |