How can we add some extra tags to DJANGO FORM MODEL tag element? I all-read tried change something inside form.py/class META/widgets but without nothing.
class MySelect( forms.Select ):
def __init__( self, attrs = None, choices = (), option_xtra_attr = '' ):
self.option_xtra_attr = option_xtra_attr
super( MySelect, self ).__init__( attrs, choices )
def render_option( self, selected_choices, option_value, option_label, option_xtra_attr = '' ):
if option_value is None:
option_value = ''
option_value = force_text( option_value )
if option_value in selected_choices:
selected_html = mark_safe( ' selected="selected"' )
if not self.allow_multiple_selected:
# Only allow for a single selection.
selected_choices.remove( option_value )
else:
selected_html = ''
return format_html( '<option value="{}"{}{}>{}</option>',
option_value,
selected_html,
option_xtra_attr,
force_text( option_label ) )
class MonitoringSpot_InLine_FORM( forms.ModelForm ):
class Meta:
model = MonitoringSpotClass
fields = [ 'monitoringSpot_NODE_monitoringAreaType', ]
widgets = {
'monitoringSpot_NODE_monitoringAreaType': MySelect( option_xtra_attr = { 'xdata': 'value' } )
}