I have to add title attribute to options of the ModelChoiceField. Here is my admin code for that:
class LocModelForm(forms.ModelForm):
def __init__(self,*args,**kwargs):
super(LocModelForm,self).__init__(*args,**kwargs)
self.fields['icons'] = forms.ModelChoiceField(queryset = Photo.objects.filter(galleries__title_slug = "markers"))
self.fields['icons'].widget.attrs['class'] = 'mydds'
class Meta:
model = Loc
widgets = {
'icons' : forms.Select(attrs={'id':'mydds'}),
}
class Media:
css = {
"all":("/media/css/dd.css",)
}
js=(
'/media/js/dd.js',
)
class LocAdmin(admin.ModelAdmin):
form = LocModelForm
I can add any attribute to select widget, but I don't know how to add attributes to option tags. Any idea?