Created
December 13, 2012 13:02
-
-
Save stefanfoulis/4276256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_select2.fields import AutoModelSelect2Field | |
from django_select2 import AutoHeavySelect2Widget | |
from django_select2.util import JSFunction | |
class MySearchWidget(AutoHeavySelect2Widget): | |
def init_options(self): | |
super(MySearchWidget, self).init_options() | |
self.options['formatResult'] = JSFunction('''function(object, container, query){return object.path + '<br/><strong style="font-size: 14px;">' + object.text + '</strong>';}''') | |
self.options['formatSelection'] = JSFunction('''function(object, container){return object.text;}''') | |
class MySearchField(AutoModelSelect2Field): | |
search_fields = ['title_set__title__icontains', 'title_set__menu_title__icontains', 'title_set__slug__icontains'] | |
widget = MySearchWidget | |
def extra_data_from_instance(self, obj): | |
breadcrumbs = [p.get_menu_title() for p in obj.get_ancestors()] | |
path = u" | ".join(breadcrumbs) | |
return { | |
'path': path, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment