Get specific field from Fieldset in Django Admin?
I'm trying to rearrange the admin form into a custom format and order by editing the change开发者_如何学JAVA_form.html and includes/fieldset.html.
Inside the fieldset.html, the Fieldset object is iterated to get the list of FieldLine and then AdminField objects (which contains the BoundForm for each model attribute).
Is there a way to access the BoundForm object directly without iterating?
I can get the name of the field attribute by using "{{ fieldset.fields.0 }}", but going beyond that doesn't yield anything. "{{ fieldset.fields.0.field.label_name }}" = nothing.
How can I get the label_name or other parts of a specific BoundForm without iterating over the entire fieldset?
You can create a simple template tag for the purpose of returning the field at a defined key. See Setting a Variable in the Context from Django docs.
Development branch has a much easier way with assignment_tag
, but it will only work currently if you're running from trunk or on future versions after 1.3. See: Assignment Tags
精彩评论