Yes, that is correct.
The usual approach would be to store the image paths and the targets in different lists and just index them in the __getitem__ method with the provided index argument.
However, you would have to make sure that the lists containing the image path and target keep their correspondence. Sorting one of them would break your training.
Alternatively you could also use a dict, and append each item as {'img_path': path, 'target': target}, but it depends on your coding style.