yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.79k stars 467 forks source link

No way to conveniently display custom labels using Select2ListView #1288

Open nabil-rady opened 2 years ago

nabil-rady commented 2 years ago

There is a very convenient method when I use Select2QuerySetView (using get_result_label), why isn't there a similar thing in ListViews ? There is only a way to change the value, but I can't find any to change the displayed labels, please let me know if I missed something.

jpic commented 1 year ago

Did you figure this out? Would you like to make a pull request?

elam91 commented 10 months ago

This is what I did

class ColorAutocompleteView(autocomplete.Select2ListView):

def get_result_with_label(self, choice):
    new_choice = (choice[0],
                  format_html('<div style="background-color:{}; width: 100%; height:100%;">{}</div>',
                                           choice[0], choice[1]))
    return new_choice

def get_list(self):
    return [self.get_result_with_label(choice) for choice in TailwindColors.choices]