For now I have not found an ability to execute reverse foreign key joins in Django more efficiently that using a prefetch_related
a.k.a. joining in python. This method would generate 1 additional query for each reverse lookup and if I have 4-5 of those they start to decrease the performance and increase execution time.
The only thing that is able to achieve that in one query is a full raw sql (not model.objects.raw()) which completely separates query results from the models (python objects) and leads to problems with drf serialization, fields renaming, testing and other stuff you can come up with. Does someone have an idea how to overcome this?
Relation example:
class Contest(models.Model):
...
class Award(models.Model):
contest = models.ForeignKey(Contest, related_name="awards")
...
Contest.objects.prefetch_related("awards") # would generate 2 queries
p.s. thanks in advance :)