django-autocomplete-light icon indicating copy to clipboard operation
django-autocomplete-light copied to clipboard

No way to conveniently display custom labels using Select2ListView

Open nabil-rady opened this issue 3 years ago • 2 comments

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.

nabil-rady avatar Mar 08 '22 23:03 nabil-rady

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

jpic avatar Sep 09 '22 20:09 jpic

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]

elam91 avatar Oct 16 '23 23:10 elam91