Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/20tab/twentytab-choicesfilter
A django app that initializes admin changelist view with select filters usin jquery-plugin select2
https://github.com/20tab/twentytab-choicesfilter
Last synced: about 1 month ago
JSON representation
A django app that initializes admin changelist view with select filters usin jquery-plugin select2
- Host: GitHub
- URL: https://github.com/20tab/twentytab-choicesfilter
- Owner: 20tab
- License: mit
- Created: 2014-05-02T21:54:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T16:39:14.000Z (about 4 years ago)
- Last Synced: 2024-11-19T22:53:23.115Z (about 2 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
```py
INSTALLED_APPS = {
...,
'select2',
'choicesfilter',
...
}
```- Static files
Run collectstatic command or map static directory.
## Usage
- models.py
```py
class MyModel(models.Model):
name = models.CharField(...)
related_obj = models.ForeignKey(MyRelated)```
- admin.py
```py
from django.contrib import admin
from mymodels.models import MyModel
from choicesfilter.admin import ChoicesFilterAdminclass 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. **