20tab / twentytab-choicesfilter

A django app that initializes admin changelist view with select filters usin jquery-plugin select2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

twentytab-choicesfilter

A django app that initializes admin changelist view with select filters usin jquery-plugin select2

Installation

Use the following command: pip install twentytab-choicesfilter

Configuration

  • settings.py
INSTALLED_APPS = {
    ...,
    'select2',
    'choicesfilter',
    ...
}
  • Static files

Run collectstatic command or map static directory.

Usage

  • models.py
class MyModel(models.Model):
    name = models.CharField(...)
    related_obj = models.ForeignKey(MyRelated)
  • admin.py
from django.contrib import admin
from mymodels.models import MyModel
from choicesfilter.admin import ChoicesFilterAdmin


class MyModelAdmin(ChoicesFilterAdmin):
    list_display = (u'name', u'related_obj')
    choicesfilter = [u'name', 'related_obj']
    choices_mandatory = False
    choicesfilter_choices = {'related_obj': RelatedClass.objects.values_list('pk', 'obj_field').all()}

admin.site.register(MyModel, MyModelAdmin)

If you want to initialize changelist admin view with empty queryset set 'choices_mandatory = True'

** REMEMBER: choicesfilter_choices MUST be a list of binary tuples like choices for a CharField **

** This app overrides {% block filters %} in change_list.html template. **

About

A django app that initializes admin changelist view with select filters usin jquery-plugin select2

License:MIT License


Languages

Language:Python 82.2%Language:HTML 10.9%Language:JavaScript 7.0%