Herding your Database Queries in Django
Django ORM allows one to seamlessly represent database (DB) data as instances of Python classes (models). This includes relationships between objects, such that when a model (A) has a foreign key relationship (let’s say field name ‘related_b’) to another model (B), all you need to do to navigate from an instance of A (a) to the related instance of B (b) is “a.related_b”. By default, this will fetch “b” from the database, which is both amazingly convenient and also terrifying. I say terrifying with some degree of jest, but also plenty of seriousness that will be appreciated by those of us who know what it’s like to deal with a production database that is melting (struggling) under load.