Skip to content

Commit

Permalink
Add support for template property
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelljkotler committed Jul 16, 2020
1 parent 096aba0 commit aa0dd87
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/dal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q
from django.http import HttpResponseBadRequest, HttpResponseNotAllowed
from django.template.loader import render_to_string
from django.views.generic.list import BaseListView

import six
Expand Down Expand Up @@ -76,6 +77,7 @@ class BaseQuerySetView(ViewMixin, BaseListView):
create_field = None
search_fields = []
split_words = None
template = None

def has_more(self, context):
"""For widgets that have infinite-scroll feature."""
Expand All @@ -87,7 +89,10 @@ def get_result_value(self, result):

def get_result_label(self, result):
"""Return the label of a result."""
return six.text_type(result)
if self.template:
return render_to_string(self.template, {"result": result})
else:
return six.text_type(result)

def get_selected_result_label(self, result):
"""Return the label of a selected result."""
Expand Down

0 comments on commit aa0dd87

Please sign in to comment.