Accessing Custom Objects
TrialGrid allows Custom Objects to be defined as child objects of drafts. These can be accessed and included in Document Templates via the draft customobject_set attribute.
{% for custom_object in draft.customobject_set.all() %}
{{custom_object.identifier}}
{% endfor %}
In the above example we list all the custom objects which belong to the draft. Normally we will be interested in one type of custom object. To get only custom objects of a certain type we can filter further:
{% for custom_object in draft.customobject_set.filter(custom_object_definition__name="Report Specification") %}
{{custom_object.identifier}}
{% endfor %}
Some custom objects can have child objects. These can be accessed through the customobject_set of the parent object:
{% for custom_object in draft.customobject_set.filter(custom_object_definition__name="Report Specification") %}
{{custom_object.identifier}}
{% for child_object in custom_object.customobject_set.filter(custom_object_definition__name="Report Column") %}
Child ->{{child_object.identifier}}
{% endfor %}
{% endfor %}
Reporting on a Custom Object listing
A Template with a Draft Object List scope is tied to a single Object Type, so when it is run from a Custom Object listing the selected_objects and filtered_objects it receives already hold only that type. There is no need to filter by custom_object_definition__name:
{% for custom_object in selected_objects %}
{{custom_object.identifier}}
{% endfor %}
Child objects are reached from there as above:
{% for custom_object in selected_objects %}
{{custom_object.identifier}}
{% for child_object in custom_object.customobject_set.filter(custom_object_definition__name="Report Column") %}
Child ->{{child_object.identifier}}
{% endfor %}
{% endfor %}
all_objects holds every object of the Template's Object Type in the Draft, whatever the user had selected or filtered to. It is narrowed to the type in the same way, so it saves the custom_object_definition__name filter shown at the top of this page:
{% for custom_object in all_objects %}
{{custom_object.identifier}}{% if custom_object.id in selected_ids %} (selected){% endif %}
{% endfor %}