Programming

Programming

Exploring Various Coding Languages

Programming LanguagesSoftware DevelopmentAlgorithms and Data StructuresSoftware EngineeringWeb and Mobile Programming

Articles in this Section

Search in Django ORM: From Basic Text Lookups to PostgreSQL Full‑Text Search

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.

/article/search-in-django-orm-from-basic-text-lookups-to-postgresql-fulltext-search

Understanding Managers in Django ORM: Custom Managers, Default Managers, Base Managers, and Advanced Usage Patterns

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.

/article/understanding-managers-in-django-orm-custom-managers-default-managers-base-managers-and-advanced-usage-patterns

Performing Raw SQL Queries in Django: RawSQL, raw(), Field Mapping, Parameters, and Safety Considerations

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.

/article/performing-raw-sql-queries-in-django-rawsql-raw-field-mapping-parameters-and-safety-considerations

Database Transaction Management in Django: atomic(), ATOMIC_REQUESTS, Savepoints, and Autocommit Behavior

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.

/article/database-transaction-management-in-django-atomic-atomic-requests-savepoints-and-autocommit-behavior

Working with Multiple Databases in Django: Configuration, Migrations, Routing, and Database Routers

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.

/article/working-with-multiple-databases-in-django-configuration-migrations-routing-and-database-routers

Using Tablespaces in Django: Table Storage, Index Placement, and Database Support

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.

/article/using-tablespaces-in-django-table-storage-index-placement-and-database-support

Database Access Optimization in Django: Profiling, QuerySet Behavior, Indexing, and Efficient Query Techniques

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.

/article/database-access-optimization-in-django-profiling-queryset-behavior-indexing-and-efficient-query-techniques

Database Query Instrumentation in Django: Using execute_wrapper to Monitor, Log, and Control Query 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.

/article/database-query-instrumentation-in-django-using-execute-wrapper-to-monitor-log-and-control-query-execution

Understanding Fixtures in Django: Creation, Loading, Discovery, Ordering, and Best Practices

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.

/article/understanding-fixtures-in-django-creation-loading-discovery-ordering-and-best-practices

A Complete Guide to Many‑to‑Many Relationships in Django with Practical Examples

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.

/article/a-complete-guide-to-manytomany-relationships-in-django-with-practical-examples

A Complete Guide to Many‑to‑One Relationships in Django Using ForeignKey

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.

/article/a-complete-guide-to-manytoone-relationships-in-django-using-foreignkey

A Complete Guide to One‑to‑One Relationships in Django Using OneToOneField

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.

/article/a-complete-guide-to-onetoone-relationships-in-django-using-onetoonefield