You can do this more concisely using a dictionary where the keys are tuples containing the boolean inputs to your if statements, and the values are the resulting three strings:
map = {
(True, False): ('reverse', 'forward', None),
(True, True): ('all_reverse', 'all_forward', 'reverse'),
(False, True): ('all_forward', 'all_reverse', 'forward'),
(False, False): ('forward', 'reverse', None),
}
traversal_function, annotation_function, item_id_query = map[(reverse_relationship, get_all_links)]
@konserw's second answer is another way to go if you want to make use of the fact that the resulting strings are built up in a logical way based on the inputs. Be aware that the solution they present results in item_query_id having a non-None value in all cases though, which doesn't match your code. To get the same results as your solution, making only a change to see that get_all_links is always defined, but is None for the cases where you don't set it in your code, you could change their answer to this:
item_id_query = None
traversal_function = 'reverse' if reverse_relationship else 'forward'
annotation_function = 'forward' if reverse_relationship else 'reverse'
if get_all_links:
item_id_query = traversal_function
traversal_function = f'all_{traversal_function}'
annotation_function = f'all_{annotation_function}'
To have this code act exactly the same as your if statements, just remove the first line of this code. I don't recommend that, as I think you'd want item_id_query to be defined in all cases.
if/elseonreverse_relationship, setting your two variables to 'forward'/'reverse' in some order, followed by anif get_all_links:that just adds 'all_' in front of those values.