
Exploring Various Coding Languages
This article explores the different search techniques available in Django ORM—from simple text lookups using contains and icontains, to advanced database‑specific search features such as unaccent and trigram similarity in PostgreSQL. It also explains when traditional string matching becomes insufficient and how document‑based search engines or PostgreSQL’s built‑in full‑text search can be used for large‑scale and multilingual search needs.
This article explains how Django Managers work, how to rename them, how to create custom managers, how to override get_queryset(), how default and base managers behave, how Django uses managers for related-object access, and how to expose custom QuerySet methods through a manager. Managers are the primary interface for database operations in Django, and understanding them is essential for writing clean, reusable, and powerful ORM logic.
This article explains Django’s three mechanisms for executing raw SQL: embedding SQL fragments using RawSQL, using Manager.raw() to return model instances, and executing SQL directly. It covers field mapping, deferred fields, indexing behavior, parameterized queries, SQL injection protection, and backend-specific considerations such as MySQL’s type coercion. Raw SQL is powerful but must be used carefully and only when the ORM cannot express the required query.
This article explains how Django manages database transactions, including its default autocommit behavior, per-request transactions using ATOMIC_REQUESTS, explicit transaction control with atomic(), nested savepoints, durability guarantees, error handling patterns, and performance considerations. It also clarifies why Django uses autocommit by default and highlights common pitfalls such as catching exceptions inside atomic blocks or inconsistent model state after rollbacks.
This article explains how Django supports multiple databases, including how to define database connections, run migrations on different databases, use management commands with database selection, and implement automatic database routing. It also covers the structure and behavior of database routers, how Django decides which database to use for reads, writes, relations, and migrations, and how hints influence routing decisions.
This article explains how Django supports tablespaces for organizing database storage. It covers how to declare tablespaces for tables and indexes, how DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE influence behavior, and how tablespaces behave across different database backends. An example model demonstrates how table and index placement works in practice.
This article provides a comprehensive guide to optimizing database access in Django. It covers profiling techniques, standard database optimizations such as indexing, understanding QuerySet evaluation and caching, using iterator() for large datasets, leveraging explain() for query analysis, and performing work inside the database rather than in Python. It also explores advanced techniques such as RawSQL and raw SQL execution.
This article explains how Django’s database instrumentation system allows developers to wrap, inspect, log, or block database queries using execute_wrapper(). It covers how wrappers work, what parameters they receive, how to implement blockers and loggers, and how to apply wrappers within a context manager. This feature is useful for debugging, performance monitoring, enforcing architectural rules, and preventing unexpected database access.
This article explains what fixtures are in Django, how to create and load them, how Django discovers fixture files, how fixture ordering works, how data is saved during fixture loading, how to safely handle signals, how compressed fixtures behave, and how to use database‑specific fixtures in multi‑database environments.
This article explains how to define and work with many‑to‑many (M2M) relationships in Django using ManyToManyField. It covers creating related objects, adding and removing relationships, querying across M2M relations, reverse lookups, using set() and clear(), handling deletions, and understanding how Django manages M2M relations internally. All concepts are demonstrated with practical Python API examples.
This article explains how to define and work with many‑to‑one relationships in Django using ForeignKey. It covers creating related objects, reverse lookups, moving objects between parents, querying across relationships, using lists and querysets in lookups, circular relationship queries, and understanding deletion behavior with CASCADE. All concepts are demonstrated with practical Python API examples.
This article explains how to define and work with one‑to‑one relationships in Django using OneToOneField. It covers creating related objects, accessing relationships from both sides, reassigning one‑to‑one links, querying across relationships, deletion behavior with CASCADE, and working with related models such as Waiter. All concepts are demonstrated with practical Python API examples.