from django_select2 import AutoSelect2MultipleField, AutoModelSelect2MultipleField
from django_select2 import NO_ERR_RESP

from .models import Dept

class GetSearchTestField(AutoSelect2MultipleField):
    """
    Selects an employee.
    This field does not render the form value on search results presentation.
    """
    def security_check(self, request, *args, **kwargs):
        return True
    def get_results(self, request, term, page, context):
        """
        Just a trivial example.
        """
        res = [('Green Gold','Green Gold'),('Hulk','Hulk'),]
        return (NO_ERR_RESP, False, res)

class GetModelSearchTestField(AutoModelSelect2MultipleField):
    """
    Selects a department.
    This field does render the form value on search results presentation. Works OK.
    """
    queryset = Dept.objects.all()
    search_fields = ['name__icontains']
    to_field = 'name'

    def security_check(self, request, *args, **kwargs):
        return True
@@ -488,16 +488,35 @@
  example
+, with fixed values
 .%0A      
@@ -624,16 +624,491 @@
 , res)%0A%0A
+    def get_val_txt(self, value):%0A        %22%22%22%0A        The problem of issue #66 was here. I was not overriding this.%0A        When using AutoSelect2MultipleField you should implement get_val_txt in this case.%0A        I think that this is because there should be an unique correspondence between%0A        the referenced value and the shown value%0A        In this particular example, the referenced value and the shown value are the same%0A        %22%22%22%0A        return unicode(value)%0A%0A
 class Ge

Fix issue #66 on my own example, implementing get_val_txt(self, value) on my overriden field.