GithubHelp home page GithubHelp logo

00mjk / django-admin-list-filter-dropdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrts/django-admin-list-filter-dropdown

0.0 0.0 0.0 21 KB

Use dropdowns in Django admin list filter

License: MIT License

Python 69.33% HTML 30.67%

django-admin-list-filter-dropdown's Introduction

django-admin-list-filter-dropdown

A Django admin filter implementation that renders as a dropdown.

If you have more than ten values for a field that you want to filter by in Django admin, the filtering sidebar gets long, cluttered and hard to use.

This app contains the DropdownFilter class that renders as a drop-down in the filtering sidebar to avoid this problem.

Usage

Install:

pip install django-admin-list-filter-dropdown

Enable in settings.py:

INSTALLED_APPS = (
    ...
    'django_admin_listfilter_dropdown',
    ...
)

Use in admin.py:

from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter

class EntityAdmin(admin.ModelAdmin):
    ...
    list_filter = (
        # for ordinary fields
        ('a_charfield', DropdownFilter),
        # for choice fields
        ('a_choicefield', ChoiceDropdownFilter),
        # for related fields
        ('a_foreignkey_field', RelatedDropdownFilter),
    )

Example of a custom filter that uses the provided template:

class CustomFilter(SimpleListFilter):
    template = 'django_admin_listfilter_dropdown/dropdown_filter.html'

    def lookups(self, request, model_admin):
        ...

    def queryset(self, request, queryset):
        ...

Example

Here's what it looks like:

Screenshot of dropdown admin filter

Credits

Based on this StackOverflow question and code from FeinCMS.

django-admin-list-filter-dropdown's People

Contributors

alexphelps avatar andreynovikov avatar ihoru avatar kunalgrover05 avatar luizrrodrigues avatar mrts 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.