paint-brush
All you need to know about prefetching in Djangoby@hakibenita
39,713 reads
39,713 reads

All you need to know about prefetching in Django

by Haki Benita
Haki Benita HackerNoon profile picture

Haki Benita

@hakibenita

April 29th, 2017
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

For a better reading experience, check out<a href="https://hakibenita.com/all-you-need-to-know-about-prefetching-in-django" target="_blank"> this article on my website.</a>
featured image - All you need to know about prefetching in Django
Haki Benita HackerNoon profile picture
Haki Benita

Haki Benita

@hakibenita

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:

image

The models looked (roughly) like this:


class Program(models.Model):name = models.CharField(max_length=20)




class Price(models.Model):program = models.ForeignKey(Program)from_date = models.DateTimeField()to_date = models.DateTimeField()



class Order(models.Model):state = models.CharField(max_length=20)items = models.ManyToManyField(Price)

  • Program is a session, lecture or a conference day.
  • Prices can change over time so we used a model called Price, modeled as a type 2 slowly changing dimension (SCD) that represents the price of a program at a certain time.
  • User’s can register to one or more programs. Each item in an Order is a program price at the time the order was made.

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 LOGGING settings in settings.py:

LOGGING = {

...     
  
'loggers': {  
    **'django.db.backends': {  
        'level': 'DEBUG',  
    },**  
},  

}

image

Let’s see you trying to find an image related to prefetching…

L O A D I N G
. . . comments & more!

About Author

Haki Benita HackerNoon profile picture
Haki Benita@hakibenita

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Habr
Statvoo
Pvsm
E-learn
Pychina
Yome
Alluxi
Libox
Fullstackfeed
Aryan
Dev