Select2 para Django con dependencias dinámicas y re-init en modales
Project description
django-vladik-select2
django-vladik-select2 es una implementación de widgets Select2 para Django, permitiendo cargar opciones dinámicamente mediante AJAX, manejar selects dependientes y ofrecer una integración simple con Bootstrap 5.
Este paquete nace como solución práctica cuando se necesitan selects que cambien según otros campos, sin recargar la página y con buen rendimiento.
Características
- Compatible con Django >=3.8
- Integración mejorada con Bootstrap 5
- Soporte para dependencias dinámicas (
depend_*) - Carga remota mediante API / AJAX
- Compatible con formularios Django regulares y CBV
- Fácil de extender y personalizar
Instalación
pip install django-vladik-select2
Modo de uso
INSTALLED_APPS = [
...
"django_vladik_select2",
]
urlpatterns = [
...
path("vladik-select2/", include("django_vladik_select2.urls")),
]
from django_vladik_select2.widgets import Select2VladikWidget, DeferredModelChoiceField, apply_dependent_selects
class PersonaForm(forms.ModelForm):
departamento = forms.ModelChoiceField(
queryset=Departamento.objects.all(),
widget=Select2VladikWidget(select_type='search', model_name='departamento')
)
provincia = DeferredModelChoiceField(
queryset=Provincia.objects.none(),
widget=Select2VladikWidget(select_type='search', model_name='provincia', depend='departamento')
)
distrito = DeferredModelChoiceField(
queryset=Distrito.objects.none(),
widget=Select2VladikWidget(select_type='source', model_name='distrito', depend='provincia')
)
etnia = DeferredModelChoiceField(
queryset=Etnia.objects.all(),
widget=Select2VladikWidget(select_type='simple', model_name='etnia', auto_load=True)
)
class Meta:
model = Persona
fields = ['nombre', 'departamento', 'provincia', 'distrito', 'etnia']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
apply_dependent_selects(self)
Incluir en la plantilla(muy importante)
{{ form.media }}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_vladik_select2-0.1.0.tar.gz.
File metadata
- Download URL: django_vladik_select2-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76b7a92876d8813bbbe711e019a8b83ef2a3d24f54fd8560345251a271710d3a
|
|
| MD5 |
e9c1738f39de8242ee714bd8a50d54eb
|
|
| BLAKE2b-256 |
51ee9c39018e6d18d64895d1c4327ad0b1650a02b3484527d955071ac5b717eb
|
File details
Details for the file django_vladik_select2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_vladik_select2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ed1e481e95387ab09974d56a3ab9f1911721886b834e8dbb30fa1c5b9ee667
|
|
| MD5 |
9d523dafa5f0d4b54f56c78b09828074
|
|
| BLAKE2b-256 |
a1a0762ab72daf873a47f79396070a7725b97d4f931d0a37d953d91d0d566e20
|