mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #13009 -- Added BoundField.widget_type property.
This commit is contained in:
parent
ab903fe304
commit
a350bfa6f4
4 changed files with 34 additions and 0 deletions
|
@ -972,6 +972,23 @@ Attributes of ``BoundField``
|
|||
>>> print(f['message'].name)
|
||||
message
|
||||
|
||||
.. attribute:: BoundField.widget_type
|
||||
|
||||
.. versionadded:: 3.1
|
||||
|
||||
Returns the lowercased class name of the wrapped field's widget, with any
|
||||
trailing ``input`` or ``widget`` removed. This may be used when building
|
||||
forms where the layout is dependent upon the widget type. For example::
|
||||
|
||||
{% for field in form %}
|
||||
{% if field.widget_type == 'checkbox' %}
|
||||
# render one way
|
||||
{% else %}
|
||||
# render another way
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
Methods of ``BoundField``
|
||||
-------------------------
|
||||
|
||||
|
|
|
@ -278,6 +278,9 @@ Forms
|
|||
* :attr:`.MultiWidget.widgets` now accepts a dictionary which allows
|
||||
customizing subwidget ``name`` attributes.
|
||||
|
||||
* The new :attr:`.BoundField.widget_type` property can be used to dynamically
|
||||
adjust form rendering based upon the widget type.
|
||||
|
||||
Generic Views
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue