1. When Shot ID is known (let's say it is 860) it is quite easy to query the Shot Name using the following syntax.
myShot = sg.find("Shot", filters=[['id', 'is', 860]], fields = ['code'])
print myShot[0]['code']
STDOUT: shot_01
2. Is there a quick way to query the linked to this Shot Tasks when both Shot Name and Shot ID are known?
I can query the Tasks using all kind of fields. But I can't find the way to filter only those Tasks that are assigned to a particular shot.
The Task's field that is used to store the data to what Shot Name the Task belongs to is stored in Dictionary form:
The field itself is called as 'entity'. This 'entity' field is actually an array of all kind of values one of which is the Shot Name the task is assigned to.
Here is the example on how the Tasks's entity field looks like:
tasks = sg.find("Task", filters=[['sg_status_list', 'is', 'ip']], fields = ['entity'])
print len(tasks)
STDOUT: 37
pprint(tasks)
STDOUT:
[
{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 6, 'type': 'Task'},
{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 7, 'type': 'Task'},
{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 8, 'type': 'Task'},
{'entity': {'id': 5, 'name': 'shot_040', 'type': 'Shot'},'id': 41,'type': 'Task'},
{'entity': {'id': 6, 'name': 'shot_050', 'type': 'Shot'},'id': 50,'type': 'Task'},
.........>>skipping an entire list here........
{'entity': {'id': 627, 'name': 'teapot', 'type': 'Asset'},'id': 162,'type': 'Task'}
]
I see it is possible to print out the individual Key value out of this Dictionary using this syntax:
pprint(tasks[1]['entity']['name'])
STDOUT: 'shot_010'
But I can't use this syntax used to print out the Tasks's Entity's Field's 'name' key value while querying with
sg.find_one command. It will give me the error if I attempt to do this:
shotTasks = sg.find("Task", filters=[['sg_status_list', 'is', 'ip'], fields= ['['entity']['name']', 'is', 'shot_010'])
STDOUT: # Error: SyntaxError: invalid syntax #