mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-05-01 02:14:50 +00:00
Merge pull request #61 from novapost/master
Fix #59 - Add a get_queryset helper to be able to provide a site related queryset.
This commit is contained in:
commit
0a77e54b59
1 changed files with 7 additions and 4 deletions
|
|
@ -139,14 +139,17 @@ class ModelResultJsonMixin(object):
|
|||
value. (Default is ``pk``, i.e. the id field of the model)
|
||||
:type to_field_name: :py:obj:`str`
|
||||
"""
|
||||
if self.queryset is None and not 'queryset' in kwargs:
|
||||
raise ValueError('queryset is required.')
|
||||
|
||||
self.max_results = getattr(self, 'max_results', None)
|
||||
self.to_field_name = getattr(self, 'to_field_name', 'pk')
|
||||
|
||||
super(ModelResultJsonMixin, self).__init__(*args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
if self.queryset is None:
|
||||
raise ValueError('queryset is required.')
|
||||
|
||||
return self.queryset
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
"""
|
||||
Sub-classes should override this to generate custom label texts for values.
|
||||
|
|
@ -246,7 +249,7 @@ class ModelResultJsonMixin(object):
|
|||
if not hasattr(self, 'search_fields') or not self.search_fields:
|
||||
raise ValueError('search_fields is required.')
|
||||
|
||||
qs = copy.deepcopy(self.queryset)
|
||||
qs = copy.deepcopy(self.get_queryset())
|
||||
params = self.prepare_qs_params(request, term, self.search_fields)
|
||||
|
||||
if self.max_results:
|
||||
|
|
|
|||
Loading…
Reference in a new issue