Closed koterpillar closed 3 years ago
Why can't you use {% url %}
to get the lookup of the url?
Also, if this is the same problem you were having the other day, why must it be a lazy reverse? Why not do the reverse in the Form init?
I can put label
in __init__
, but that still leaves a chunk of HTML in the Python file. I never said I couldn't use {% url %}
, though.
I don't remember why I needed this anymore...
Motivation
I have the following widgets (simplified for brevity):
For a particular use case, I want to generate the following:
Where
/somewhere
is a result ofreverse('some_view')
.The hacky solution is set the label of the form field to the HTML and mark it safe. However, due to circular imports and
mark_safe
not playing along withreverse_lazy
this isn't feasible, and besides, HTML belongs in the templates.Solution
Sniplates has
nested_widget
, but it forces the variable name to becontent
, notlabel
, and doesn't have the automatic attribute extraction of theform_field
.Mild option
Upon seeing
nested_content_for
,form_field
parses the inside content and assigns the result tolabel
in the context.widget
works the same.nested_widget
is deprecated as it is equivalent to{% widget nested_content_for='content' %}
.If
nested_content_for
is not specified as an argument forform_field
orwidget
, they behave like now.Crazy option
Upon seeing
nested
as an attribute,form_field
(andwidget
) look for{% attribute ... %}
sections and add their result to the context. The advantage over the first option is the ability to specify multiple inline arguments.I'm not particularly attached to the wording, etc. If you're okay with either option, I can write up a PR.