Good morning,
I use the widgets ModelSelect2Multiple and ModelSelect2 and in the view i used the get_selected_result_label and get_result_label to return html with image and text for get_result_label and only html image to get_selected_result_label and this work's fine!
But when i load a form with an instance for editing the entrance on database the widget don't load the declared html format, just simple text with de x mark to exclude, even if i remove and add the same item again the widget doesn't load with the html.
Best regards.
Just to check - did you set the data-html attribute on your widget?
class PersonForm(forms.ModelForm):
class Meta:
widgets = {
'birth_country': autocomplete.ModelSelect2(
url='country-autocomplete',
attrs={'data-html': True}
)
}
Just to check - did you set the
data-htmlattribute on your widget?class PersonForm(forms.ModelForm): class Meta: widgets = { 'birth_country': autocomplete.ModelSelect2( url='country-autocomplete', attrs={'data-html': True} ) }
Yes i'm using.
I'm attaching the images with the behavior, in the first i don't have anything on the instance, but in the second i have.
Best regards,


In your models.py, what is your __str__ method?
I think the only way to have it be an image is if you update your __str__ method to return an image. I faced a similar problem a while back but couldn't solve it.
In your models.py, what is your
__str__method?I think the only way to have it be an image is if you update your
__str__method to return an image. I faced a similar problem a while back but couldn't solve it.
Thank you, it's a good approach to solve, now i can see my image, not yet the best way because i have other issues to solve, maybe i will change the layout of the web application and things will work fine!
Best regards!
Most helpful comment
Thank you, it's a good approach to solve, now i can see my image, not yet the best way because i have other issues to solve, maybe i will change the layout of the web application and things will work fine!
Best regards!