Skip to content

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

License

Notifications You must be signed in to change notification settings

20tab/twentytab-choicesfilter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published