Contains all the Django fields for Select2.
Bases: object
Registers itself with AutoResponseView.
All Auto fields must sub-class this mixin, so that they are registered.
Warning
Do not forget to include 'django_select2.urls' in your url conf, else, central view used to serve Auto fields won’t be available.
Class constructor.
| Parameters: | auto_id (unicode) – The key to use while registering this field. If it is not provided then an auto generated key is used. Tip This mixin uses full class name of the field to register itself. This is used like key in a dict by util.register_field(). If that key already exists then the instance is not registered again. So, eventually all instances of an Auto field share one instance to respond to the Ajax queries for its fields. If for some reason any instance needs to be isolated then auto_id can be used to provide a unique key which has never occured before. |
|---|
Returns False if security check fails.
| Parameters: |
|
|---|---|
| Returns: | A boolean value, signalling if check passed or failed. |
| Return type: |
Warning
Sub-classes should override this. You really do not want random people making Http reqeusts to your server, be able to get access to sensitive information.
Bases: django.forms.fields.ChoiceField
Drop-in Select2 replacement for forms.ChoiceField.
alias of Select2Widget
Bases: django.forms.fields.MultipleChoiceField
Drop-in Select2 replacement for forms.MultipleChoiceField.
alias of Select2MultipleWidget
Bases: object
Makes heavy_data.js parsable JSON response for queries on its model.
On query it uses prepare_qs_params() to prepare query attributes which it then passes to self.queryset.filter() to get the results.
It is expected that sub-classes will defined a class field variable search_fields, which should be a list of field names to search for.
Class constructor.
| Parameters: |
|
|---|
Sub-classes should override this to generate custom label texts for values.
| Parameters: | obj (django.model.Model) – The model object. |
|---|---|
| Returns: | The label string. |
| Return type: | unicode |
Prepares queryset parameter to use for searching.
| Parameters: |
|
|---|---|
| Returns: | A dictionary of parameters to ‘or’ and ‘and’ together. The output format should be {
'or': [
Q(attr11=term11) | Q(attr12=term12) | ...,
Q(attrN1=termN1) | Q(attrN2=termN2) | ...,
...],
'and': {
'attrX1': termX1,
'attrX2': termX2,
...
}
}
The above would then be coaxed into filter() as below: queryset.filter(
Q(attr11=term11) | Q(attr12=term12) | ...,
Q(attrN1=termN1) | Q(attrN2=termN2) | ...,
...,
attrX1=termX1,
attrX2=termX2,
...
)
In this implementation, term11, term12, termN1, ... etc., all are actually search_term. Also then and part is always empty. So, let’s take an example. Assume, search_term == 'John'
self.search_fields == ['first_name__icontains', 'last_name__icontains']
So, the prepared query would be: {
'or': [
Q(first_name__icontains=search_term) | Q(last_name__icontains=search_term)
],
'and': {}
}
|
| Return type: |
See views.Select2View.get_results().
This implementation takes care of detecting if more results are available.
Bases: type
This does some pretty nasty hacky stuff, to make sure users can also define queryset as class-level field variable, instead of passing it to constructor.
Bases: object
Simple mixin which provides a property – choices. When choices is set, then it sets that value to self.widget.choices too.
Bases: django_select2.fields.ChoiceMixin
Overrides choices‘ getter to return instance of ModelChoiceIterator instead.
Bases: django_select2.fields.ModelChoiceField
Light Select2 field, specialized for Models.
Select2 replacement for forms.ModelChoiceField.
alias of Select2Widget
Bases: django_select2.fields.ModelMultipleChoiceField
Light multiple-value Select2 field, specialized for Models.
Select2 replacement for forms.ModelMultipleChoiceField.
alias of Select2MultipleWidget
Bases: object
Base mixin field for all Heavy fields.
Note
Although Heavy fields accept choices parameter like all Django choice fields, but these fields are backed by big data sources, so choices cannot possibly have all the values.
For Heavies, consider choices to be a subset of all possible choices. It is available because users might expect it to be available.
Class constructor.
| Parameters: |
|
|---|
Warning
Either of data_view or widget must be specified, else ValueError would be raised.
Bases: django_select2.fields.ChoiceMixin, django.forms.fields.Field
Reimplements django.forms.TypedChoiceField in a way which suites the use of big data.
Note
Although this field accepts choices parameter like all Django choice fields, but these fields are backed by big data sources, so choices cannot possibly have all the values. It is meant to be a subset of all possible choices.
Sub-classes can set this other value if needed.
Coerces value to a Python data type.
Sub-classes should override this if they do not want unicode values.
Sub-classes can override this to validate the value entered against the big data.
| Parameters: | value (As coerced by coerce_value().) – Value entered by the user. |
|---|---|
| Returns: | True means the value is valid. |
If Heavy widgets encounter any value which it can’t find in choices then it calls this method to get the label for the value.
| Parameters: | value (As coerced by coerce_value().) – Value entered by the user. |
|---|---|
| Returns: | The label for this value. |
| Return type: | unicode or None (when no possible label could be found) |
Bases: django_select2.fields.HeavyChoiceField
Reimplements django.forms.TypedMultipleChoiceField in a way which suites the use of big data.
Note
Although this field accepts choices parameter like all Django choice fields, but these fields are backed by big data sources, so choices cannot possibly have all the values. It is meant to be a subset of all possible choices.
alias of MultipleHiddenInput
Bases: django_select2.fields.HeavySelect2FieldBaseMixin, django_select2.fields.HeavyChoiceField
Heavy Select2 Choice field.
alias of HeavySelect2Widget
Bases: django_select2.fields.HeavySelect2FieldBaseMixin, django_select2.fields.HeavyMultipleChoiceField
Heavy Select2 Multiple Choice field.
alias of HeavySelect2MultipleWidget
Bases: django_select2.fields.HeavySelect2FieldBaseMixin, django_select2.fields.ModelChoiceField
Heavy Select2 Choice field, specialized for Models.
alias of HeavySelect2Widget
Bases: django_select2.fields.HeavySelect2FieldBaseMixin, django_select2.fields.ModelMultipleChoiceField
Heavy Select2 Multiple Choice field, specialized for Models.
alias of HeavySelect2MultipleWidget
Bases: django_select2.fields.AutoViewFieldMixin, django_select2.fields.HeavySelect2ChoiceField
Auto Heavy Select2 field.
This needs to be subclassed. The first instance of a class (sub-class) is used to serve all incoming json query requests for that type (class).
Warning
NotImplementedError would be thrown if get_results() is not implemented.
alias of AutoHeavySelect2Widget
Bases: django_select2.fields.AutoViewFieldMixin, django_select2.fields.HeavySelect2MultipleChoiceField
Auto Heavy Select2 field for multiple choices.
This needs to be subclassed. The first instance of a class (sub-class) is used to serve all incoming json query requests for that type (class).
Warning
NotImplementedError would be thrown if get_results() is not implemented.
alias of AutoHeavySelect2MultipleWidget
Bases: django_select2.fields.ModelResultJsonMixin, django_select2.fields.AutoViewFieldMixin, django_select2.fields.HeavyModelSelect2ChoiceField
Auto Heavy Select2 field, specialized for Models.
This needs to be subclassed. The first instance of a class (sub-class) is used to serve all incoming json query requests for that type (class).
alias of AutoHeavySelect2Widget
Bases: django_select2.fields.ModelResultJsonMixin, django_select2.fields.AutoViewFieldMixin, django_select2.fields.HeavyModelSelect2MultipleChoiceField
Auto Heavy Select2 field for multiple choices, specialized for Models.
This needs to be subclassed. The first instance of a class (sub-class) is used to serve all incoming json query requests for that type (class).
alias of AutoHeavySelect2MultipleWidget