For a better reading experience, check out this article on my website. I have recently worked on a ticket ordering system for a conference. It was very important for the customer to see a table of orders including a column with a list of program names in each order: The models looked (roughly) like this: class (models.Model):name = models.CharField(max_length=20) Program class (models.Model):program = models.ForeignKey(Program)from_date = models.DateTimeField()to_date = models.DateTimeField() Price class (models.Model):state = models.CharField(max_length=20)items = models.ManyToManyField(Price) Order is a session, lecture or a conference day. Program Prices can change over time so we used a model called , modeled as a (SCD) that represents the price of a program at a certain time. Price type 2 slowly changing dimension User’s can register to one or more programs. Each item in an is a program price at the time the order was made. Order Before we start Throughout this article we are going to monitor the queries executed by Django. To log the queries add the following to the settings in : LOGGING settings.py LOGGING = { ... 'loggers': { **'django.db.backends': { 'level': 'DEBUG', },** }, } Let’s see you trying to find an image related to prefetching…