1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
API Documentation
=================
Configuration
-------------
.. automodule:: django_select2.conf
:members:
:undoc-members:
:show-inheritance:
Widgets
-------
.. automodule:: django_select2.forms
:members:
:undoc-members:
:show-inheritance:
URLs
----
.. automodule:: django_select2.urls
:members:
:undoc-members:
:show-inheritance:
Views
-----
.. automodule:: django_select2.views
:members:
:undoc-members:
:show-inheritance:
Cache
-----
.. automodule:: django_select2.cache
:members:
:undoc-members:
:show-inheritance:
JavaScript
----------
DjangoSelect2 handles the initialization of select2 fields automatically. Just include
``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it!
If you insert forms after page load or if you want to handle the initialization
yourself, DjangoSelect2 provides a jQuery plugin, replacing and enhancing the Select2
plugin. It will handle both normal and heavy fields. Simply call
``djangoSelect2(options)`` on your select fields.::
$('.django-select2').djangoSelect2();
You can pass see `Select2 options <https://select2.github.io/options.html>`_ if needed::
$('.django-select2').djangoSelect2({placeholder: 'Select an option'});
Please replace all your ``.select2`` invocations with the here provided
``.djangoSelect2``.
Security & Authentication
-------------------------
Security is important. Therefore make sure to read and understand what
the security measures in place and their limitations.
Set up a separate cache. If you have a public form that uses a model widget
make sure to setup a separate cache database for Select2. An attacker
could constantly reload your site and fill up the select2 cache.
Having a separate cache allows you to limit the effect to select2 only.
You might want to add a secure select2 JSON endpoint for data you don't
want to be accessible to the general public. Doing so is easy::
class UserSelect2View(LoginRequiredMixin, AutoResponseView):
pass
class UserSelect2WidgetMixin(object):
def __init__(self, *args, **kwargs):
kwargs['data_view'] = 'user-select2-view'
super(UserSelect2WidgetMixin, self).__init__(*args, **kwargs)
class MySecretWidget(UserSelect2WidgetMixin, ModelSelect2Widget):
model = MySecretModel
search_fields = ['title__icontains']
|