Skip to main content

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 VladikSelect2Widget, DeferredModelChoiceField, apply_dependent_selects

class PersonaForm(forms.ModelForm):
    departamento = forms.ModelChoiceField(
        queryset=Departamento.objects.all(),
        widget=VladikSelect2Widget(select_type='search', model_name='departamento')
    )

    provincia = DeferredModelChoiceField(
        queryset=Provincia.objects.none(),
        widget=VladikSelect2Widget(select_type='search', model_name='provincia', depend='departamento')
    )

    distrito = DeferredModelChoiceField(
        queryset=Distrito.objects.none(),
        widget=VladikSelect2Widget(select_type='source', model_name='distrito', depend='provincia')
    )

    etnia = DeferredModelChoiceField(
        queryset=Etnia.objects.all(),
        widget=VladikSelect2Widget(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_vladik_select2-0.1.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_vladik_select2-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file django_vladik_select2-0.1.1.tar.gz.

File metadata

  • Download URL: django_vladik_select2-0.1.1.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

Hashes for django_vladik_select2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6c3c7befe26ca9eb53734dd72a3970444469d6d1e505f6ff96a27e81e0f00c1e
MD5 5314039a9e3503b4012db834fb6d3919
BLAKE2b-256 c0ed252b81f8f32f832be297822d4267b0d219af8f4c883cecf9f688a0dfd0b9

See more details on using hashes here.

File details

Details for the file django_vladik_select2-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_vladik_select2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 082308b660d7aa8348ff721ef4fc7d41e5e54cb4f08d8b83e26ff994d9fc1c0d
MD5 ab31b3c8c4bbd0067e8650aa32fef9f4
BLAKE2b-256 c89c7debe1d10366417ce143c4e1edabddf39853d96fefec53c4570465e59f24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page