Giter Club home page Giter Club logo

django-admin-numeric-filter's Introduction

Screenshot

django-admin-numeric-filter

django-admin-numeric-filter provides you several filter classes for Django admin which you can use to filter results in change list. It works in list_filter when a field name is defined as list where the first value is field name and second one is custom filter class (you can find classes below).

Don't forget to inherit your model admin from admin_actions.admin.NumericFilterModelAdmin to load custom CSS styles and JavaScript files declared in inner Media class.

Getting started

  1. Installation
pip install django-admin-numeric-filter
pip install git+https://[email protected]/lukasvinclav/django-admin-numeric-filter.git
  1. Add admin_numeric_filter into INSTALLED_APPS in your settings file before django.contrib.admin.

Sample admin configuration

from admin_numeric_filter.admin import NumericFilterModelAdmin, SingleNumericFilter, RangeNumericFilter, \
    SliderNumericFilter

from .models import YourModel


class CustomSliderNumericFilter(SliderNumericFilter):
    MAX_DECIMALS = 2
    STEP = 10


@admin.register(YourModel)
class YourModelAdmin(NumericFilterModelAdmin):
    list_filter = (
        ('field_A', SingleNumericFilter), # Single field search, __gte lookup
        ('field_B', RangeNumericFilter), # Range search, __gte and __lte lookup
        ('field_C', SliderNumericFilter), # Same as range above but with slider
        ('field_D', CustomSliderNumericFilter), # Filter with custom attributes
    )

Filter classes

Class name Description
admin_actions.admin.SingleNumericFilter Single field search, __gte lookup
admin_actions.admin.RangeNumericFilter Range search, __gte and __lte lookup
admin_actions.admin.SliderNumericFilter Same as range above but with slider

Slider default options for certain field types

Django model field Step Decimal places
django.db.models.fields.DecimalField() Based on decimal places max precision from DB
django.db.models.fields.FloatField() Based on decimal places field decimal_places attr
django.db.models.fields.IntegerField() 1 0

django-admin-numeric-filter's People

Contributors

tuky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.