Select2GroupQuerySetView and 'descricao'
Rastopapola opened this issue · 2 comments
django-autocomplete-light 3.8.2
Hi everyone,
first of all: I love your work on this package so much! It makes my life - and surely that of a lot of other people - a lot easier!
Now let's get to the real stuff.
Background
I always used Select2QuerySetView
as my default base class for different autocomplete functionalities. In my current project, I need to provide parent-child info of selectable data, so a user is able to see directly which entry belongs to which parent topic. Straight forward.
Select2GroupQuerySetView
Since I knew you are using Select2
and the optgroup
html tag provides grouping of choices as well, there had to be a grouping view somewhere. Since this case might be a little more special, I couldn't find it on the documentation, but succeeded on your source code.
So far so good. But there is one thing, that is not explained on the source code and neither on the documentation. It's this part, that leaves me head scratching:
class Select2GroupQuerySetView(Select2QuerySetView):
"""List of grouped options for a Select2 widget.
.. py:attribute:: group_by_related
Name of the field for the related Model on a One to Many relation
.. py:attribute:: related_field_name
Name of the related Model field to run filter against.
"""
group_by_related = None
related_field_name = 'name'
def get_results(self, context):
"""Return the options grouped by a common related model.
Raises ImproperlyConfigured if self.group_by_name is not configured
"""
...
return [{
'id': None,
'text': group,
'children': [{
'id': result.id,
'text': getattr(result, self.related_field_name),
'title': result.descricao
} for result in results]
} for group, results in groups.items()]
Who and what is descricao
? Since this attribute is mandatory on the provided choice models, I had to workaround like this
class AutocompleteModel:
...
@property
def descricao(self):
return None
Question
What is descricao and where can I find more information on this in the docs?
Thanks a lot!
Update
I just discovered the following issue and related pull request, which is the origin of the above mentioned code snippet #1186
It looks like this has been changed on a recent version of dal
which is not installed by default as the most current version by pip
: #1267
@jpic
If I see this correctly, an update on at least 3.9.0-rc1 would be required to solve this whole issue?