1👍
✅
form["testField"]
(or {{ form.testField }}
in a template) will yield a BoundField
(cf https://docs.djangoproject.com/en/1.6/ref/forms/api/#django.forms.BoundField).
To access the Field
object itself you need form["testField"].field
(or {{ form.testField.field }}
– or just {{ field.field }}
if you’re iterating on the form’s bouldfields – in the template).
Also there’s a bug in your call to super()
, it should be:
super(MyCustomField, self).__init__(*args, **kwargs)
not
super(Models.CharField, self).__init__(*args, **kwargs)
And finally: the form’s fields are NOT the model’s fields. If {{ field }}
is one of your form’s fields, it’s just a totally different (and unrelated) object.
Source:stackexchange.com