django-autocomplete-light edit form

Created on 17 Sep 2018  路  4Comments  路  Source: yourlabs/django-autocomplete-light

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.

Most helpful comment

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!

All 4 comments

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-html attribute 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,
asdf1
asdf2

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandenhall picture brandenhall  路  9Comments

Guilouf picture Guilouf  路  3Comments

nameisnot picture nameisnot  路  7Comments

raratiru picture raratiru  路  4Comments

mrname picture mrname  路  9Comments