[Django]-Django custom forms select tag

2👍

In order to change how Django renders list items you need to override that field’s widget.

See the Customizing widget instances in the documentation.

And Overriding the default field types or widgets.

Finally, if this doesn’t give you enough control, you can write your own custom widget. Here is an example of a custom widget for working with key-value pairs. However, the only part you should be concerned with is the render() method. You could extend a built in list widget, override the render() method and make it spit out the html you want.

👤Soviut

13👍

I suppose you could construct the html yourself.

<select name="{{ form.island_group.name }}">
    {% for instance in form.island_group.field.queryset %}
        <option value="{{ instance.pk }}">{{ instance.name }} yarr</option>
    {% endfor %}
</select>

Leave a comment