All Projects → aayulogic → filtermapbackend

aayulogic / filtermapbackend

Licence: GPL-3.0 license
FilterMapBackend for django-rest-framework

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to filtermapbackend

token-authentication-django
This is django app used to explain the tutorial present on https://medium.com/@shubhambansal_89125/token-based-authentication-for-django-rest-framework-44586a9a56fb
Stars: ✭ 27 (+68.75%)
Mutual labels:  django-rest-framework
drftest
drftest is a minimal testing library that aims to facilitate writing tests for django rest framework views. It also [optionally] generates good looking API documentations based on tests it runs.
Stars: ✭ 26 (+62.5%)
Mutual labels:  django-rest-framework
drf-action-serializer
A serializer for the Django Rest Framework that supports per-action serialization of fields.
Stars: ✭ 48 (+200%)
Mutual labels:  django-rest-framework
drf-jwt-example
Code samples of the tutorial "How to Use JWT Authentication with Django REST Framework"
Stars: ✭ 31 (+93.75%)
Mutual labels:  django-rest-framework
react-tutorial
A react-tutorial
Stars: ✭ 99 (+518.75%)
Mutual labels:  django-rest-framework
bk-user
蓝鲸用户管理是蓝鲸智云提供的企业组织架构和用户管理解决方案,为企业统一登录提供认证源服务。
Stars: ✭ 31 (+93.75%)
Mutual labels:  django-rest-framework
django-flag-app
A pluggable django application that adds the ability for users to flag(or report) your models.
Stars: ✭ 13 (-18.75%)
Mutual labels:  django-rest-framework
CloudCV
☁️ CloudCV Website
Stars: ✭ 53 (+231.25%)
Mutual labels:  django-rest-framework
ujson drf
JSON Renderer and Parser for Django Rest Framework using the ultra fast json (in C).
Stars: ✭ 14 (-12.5%)
Mutual labels:  django-rest-framework
drf-registration
Simple user registration package based on Django Rest Framework. DRF Registration - The easy way to generate registration RESTful APIs
Stars: ✭ 32 (+100%)
Mutual labels:  django-rest-framework
studyportal-nexus
Backend API for studyportal
Stars: ✭ 24 (+50%)
Mutual labels:  django-rest-framework
django-rest-witchcraft
Django REST Framework integration with SQLAlchemy
Stars: ✭ 38 (+137.5%)
Mutual labels:  django-rest-framework
Footprint
Bluetooth Beacon 을 활용한 장소 기반 추억 기록 및 공유 서비스
Stars: ✭ 24 (+50%)
Mutual labels:  django-rest-framework
TA-BOT
An open source Telegram bot which can be used as a teaching assistant bot if you are trying to find an easy and secure way to communicate with your students.
Stars: ✭ 20 (+25%)
Mutual labels:  django-rest-framework
django-learning-pathway
(Currently in development) Learning pathways for learning Django.
Stars: ✭ 35 (+118.75%)
Mutual labels:  django-rest-framework
drf-angular-docker-tutorial
Dockerized Django Back-end API using DRF with Angular Front-end Tutorial
Stars: ✭ 53 (+231.25%)
Mutual labels:  django-rest-framework
vstutils
Small framework for easy generates web-applications (SPA or Single Page Application).
Stars: ✭ 39 (+143.75%)
Mutual labels:  django-rest-framework
DjangoUnboxed
Production ready django based starter kit
Stars: ✭ 67 (+318.75%)
Mutual labels:  django-rest-framework
Malicious-Urlv5
A multi-layered and multi-tiered Machine Learning security solution, it supports always on detection system, Django REST framework used, equipped with a web-browser extension that uses a REST API call.
Stars: ✭ 35 (+118.75%)
Mutual labels:  django-rest-framework
Deep-learning-model-deploy-with-django
Serving a keras model (neural networks) in a website with the python Django-REST framework.
Stars: ✭ 76 (+375%)
Mutual labels:  django-rest-framework

FilterMapBackend

Test Status Imports: isort PyPI version

Table Of Content

Introduction

FilterBackend which takes mapping of query params to field name.

It takes the query_param to filter map and enables filter option in list view.

Installation

Install drf-filtermapbackend using

pip install drf-filtermapbackend

Then include filter_map in your installed apps

INSTALLED_APPS = [
    ...,
    'rest_framework',
    'filter_map',
    ...
]

Usage

You can use FilterMapBackend by adding it to your filter backends and setting filter_map attribute. For example

from rest_framework.viewsets import ModelViewSet
from filter_map.backends import FilterMapBackend

class ProfileViewSet(ModelViewSet):
    """
    Consider Profile Model has user FK,
    """
    queryset = ...
    serializer_class = ...
    filter_backends = (FilterMapBackend,)
    filter_map = {
        # plain map
        'first_name': 'user__first_name',
        
        # used with lte operator
        'joined_before': 'date_joined__date__lte',
        
        # also supports separate field name and operator 
        'last_name': ('user__last_name', 'iexact'),
    }
    

You can also define get_filter_map method to return the filter map. This will allow you to change filter_map in runtime. Here's an example

from rest_framework.viewsets import ModelViewSet
from filter_map.backends import FilterMapBackend

class ProfileViewSet(ModelViewSet):
    """
    Consider Profile Model has user FK,
    """
    queryset = ...
    serializer_class = ...
    filter_backends = (FilterMapBackend,)
    
    def get_filter_map(self):
        # Disable joined_before filter for non staff users
        if self.request.user.is_authenticated and self.request.user.is_staff:
            return {
                'first_name': 'user__first_name',
                'joined_before': 'date_joined__date__lte',
                'last_name': ('user__last_name', 'iexact'),
            }
        else:
            return {
                'first_name': 'user__first_name',
                'last_name': ('user__last_name', 'iexact'),
            }
            
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].