How to gain specific field value manually in django admin fieldsets
I'm overriding admin/includes/app-name/fieldset.html
to change the behavior of some fields using the JavaScript.
In the original fieldset.html by django theres a loop to display the fields, But I want to pick the value of first field for some usecase. How can I do that
# I removed some code to make it simpler to read
{% for line in fieldset %}
{% for field in line %}
{{ field.field }}
{% endfor %}
{% endfor %}
I'm trying
{{ fieldset[0].field }}
But this gives the error:
Could not parse the remainder: '[1].field' from 'fieldset[1].field'
If i do that
{{ fieldset }}
This gives
<django.contrib.admin.helpers.Fieldset object at 0x000002873F9B1940>
How I can Pick the data of first field instead of running a loop. I'm not fully aware of django template tags. So your help would be needed here.
I believe it would be this: {{fieldset.0.0.field}}
Thought Process:
{% for line in fieldset %}
means fieldset is an List
{% for field in line %}
means line is an List
So we're looking at something like:
fieldset = [
[fieldObj0, fieldObj1], # Line 0
[fieldObj2, fieldObj3], # Line 1
]
Get Line 0 (first line):
{{fieldset.0}}
= [fieldObj0, fieldObj1]
Get first fieldObj in Line 0:
{{fieldset.0.0}}
= fieldObj0
Get field attribute of the first fieldObj in the first line
{{fieldset.0.0.field}}
= fieldObj0.field
Hopefully that's correct