You can add this code to a file named "field_attrs.py" in a templatetags folder inside an application.
To use it, remember to load the file with the following template tag:
{% load field_attrs %}
And for each field you want to change the widget's attr:
{{ form.phone|attr:"style=width:143px;background-color:yellow"|attr:"size=30" }}
1 2 3 4 5 6 7 8 9 | from django import template
register = template.Library()
@register.filter_function
def attr(obj, arg1):
att, value = arg1.split("=")
obj.field.widget.attrs[att] = value
return obj
|
More like this
- Image compression before saving the new model / work with JPG, PNG by Schleidens 2 weeks, 2 days ago
- Help text hyperlinks by sa2812 1 month, 1 week ago
- Stuff by NixonDash 3 months, 2 weeks ago
- Add custom fields to the built-in Group model by jmoppel 5 months, 3 weeks ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 9 months ago
Comments
Please login first before commenting.