django-simple-select2
This simple django app enables users to do a few tweaks to Django's built-in autocomplete feature.
Installation
pip install django-simple-select2
Usage
models.py
class Publication(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Reporter(models.Model):
full_name = models.CharField(max_length=50)
email = models.EmailField()
def __str__(self):
return self.full_name
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
publications = models.ManyToManyField(Publication)
reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)
def __str__(self):
return self.headline
admin.py
from django.contrib import admin
from .models import Article
from simple_select2 import Select2Admin, AutoCompleteSelect2, AutoCompleteSelect2Multiple
class ArticleModelAdmin(Select2Admin, admin.ModelAdmin):
extra = {
'publications': AutoCompleteSelect2Multiple(url='select2-publication-list'),
'reporter': AutoCompleteSelect2(url='select2-reporter-list')
}
admin.site.register(Article, ArticleModelAdmin)
views.py
from simple_select2 import AutoCompleteBaseView
from .models import Reporter, Publication
class ReporterView(AutoCompleteBaseView):
model = Reporter
search_fields = ('full_name', 'email')
class PublicationView(AutoCompleteBaseView):
model = Publication
search_fields = ('name',)
#urls.py
from django.urls import path
from .views import ReporterView, PublicationView
urlpatterns = [
path('reporter/', ReporterView.as_view(), name='select2-reporter-list'),
path('publication/', PublicationView.as_view(), name='select2-publication-list'),
...
]
Settings
SIMPLE_SELECT2_THEME
Sets the project-wide default theme
to be used by Select2 for all widgets inheriting from AutoCompleteSelect2Mixin.
Can be overridden per widget using parameter theme.
Supported values are:
None(or unset) will use theme"admin-autocomplete". This is the default."admin-autocomplete"uses the theme of Django Admin."bootstrap4"uses a bundled copy of Takashi Kanemoto's select2-bootstrap4-theme. Please note that this theme requires that you pull in Bootstrap 4 CSS and JavaScript assets in your templates somewhere yourself."classic"uses the old classic theme of upstream Select2. Not much different from theme"admin-autocomplete"."default"uses the default upstream theme of Select2.
SIMPLE_SELECT2_WIDTH
Sets the project-wide default width
to be used by Select2 for all widgets inheriting from AutoCompleteSelect2Mixin.
Can be overridden per widget using parameter width.
For supported values, please check the official documentation of parameter width of Select2.
By default, django-simple-select2 does not enforce any width on Select2.
Demo
You will find a simple demo app here, simple-select2-demo
Metadata
Release files for django-simple-select2 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-simple-select2-0.2.0.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_simple_select2-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / django-simple-select2-0.2.0.tar.gz
| Download URL | django-simple-select2-0.2.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5473b41776dc178588631aa92bf7638256221424149ae2e855a02f64e3e4e3f
|
|
BLAKE2b-256 checksum How to use checksums |
9e4c57b1ec6159221d86cd99e7c84a6da2eaa00b636817fb889428f95c369f47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
|
Release files / django_simple_select2-0.2.0-py3-none-any.whl
| Download URL | django_simple_select2-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f92c3dfb44a95955de14934ef6ee56d2230ffa4eff3e11dc84ba53d2d02a600
|
|
BLAKE2b-256 checksum How to use checksums |
11a6b36f77e0f542d26c56da6ba1ddab1ef6c1dbc02eba2d509ffcf9d745f704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
|