Closed c0d3z3r0 closed 9 years ago
I modified __getitem__
in the MultiForm class but that only works for two forms with unique field names.
def __getitem__(self, key):
try:
return self.forms[key]
except KeyError:
return {x.name: x for x in
chain.from_iterable(self.forms.values())}[key]
My solution raises more problems than it solves... maybe that was a bad idea ;)
{{ form.user.username }} works. Is this intended?
Yup, it sounds as if you're worked this all out. For fine grained access to fields the {{ form.user.username }}
approach is the the intended approach. Direct access to fields causes problems if forms share field names.
I'm going to go ahead and close the bug!
Perhaps some documentation might help here?
-rocky 2015年10月12日 上午3:39,"Julian Andrews" notifications@github.com写道:
{{ form.user.username }} works. Is this intended?
Yup, it sounds as if you're worked this all out. For fine grained access to fields the {{ form.user.username }} approach is the the intended approach. Direct access to fields causes problems if forms share field names.
I'm going to go ahead and close the bug!
— Reply to this email directly or view it on GitHub https://github.com/fusionbox/django-betterforms/issues/36#issuecomment-147238631 .
I was thinking about that. The docs do have a snippet that describes this in a view context, which sort of implies the use in templates"
form = UserProfileMultiForm()
# get the Field object
form['user'].fields['name']
# get the BoundField object
form['user']['name']
But possibly that section could be fleshed out to include a short template example to make it really explicit.
I'm trying to view two ModelForms through MultiModelForm with a FormView. In the template I can't view single fields using e.g.
{{ form.username }}
while using a loop like below works.Edit: {{ form.user.username }} works. Is this intended?