Debian Codegraph @

docs/django_select2.rst

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