A quick introduction to SQL BETWEEN operator In SQL, you use the BETWEEN operator to check if a value is between two values: field_name BETWEEN low_value AND high_valueCode language: Python (python) It’s equivalent to the following: field_name >= low_value AND field_name <= high_valueCode language: Python (python) The BETWEEN operator returns true if the field_name is between low_value and high_value.Continue Reading

Introduction to the Django In We’ll use the Employee model in the HR application for the demonstration. The Employee model maps to the hr_employee table in the database: The SQL IN operator returns true if a value is in a set of values: field_name IN (v1, v2, …)Code language: Python (python) For example, you can use the IN operator to query theContinue Reading

We’ll use the Employee models from the HR application for the demonstration. The Employee model maps to the hr_employee table in the database: startswith and istartswith Sometimes, you want to check if a string starts with a substring. For example, you may want to find employees whose first name starts with Je. To do that inContinue Reading

Introduction to the Django order_by() method When defining a model, you can specify the default order of the results returned by a QuerySet by using the ordering option in the model’s Meta class. We’ll use the Employee model for the demonstration. The Employee model maps to the hr_employee table in the database: For example, to sort theContinue Reading

In practice, you rarely get all the rows from one or more tables in the database. Instead, you get a subset of rows for displaying on a web page. Django uses the slicing syntax to limit a QuerySet to a specific number of objects. Behind the scenes, Django executes a SQL SELECT statement with LIMIT and OFFSET clauses. Suppose youContinue Reading

In a many-to-many relationship, multiple rows in a table are associated with multiple rows in another table. To establish a many-to-many relationship, relational databases use a third table called the join table and create two one-to-many relationships from the source tables. Typically, the join table contains the id values of the source tablesContinue Reading

Introduction to the Django Many-to-Many relationship In a many-to-many relationship, multiple rows in a table are associated with multiple rows in another table. For example, an employee may have multiple compensation programs and a compensation program may belong to multiple employees. Therefore, multiple rows in the employee table are associatedContinue Reading

Introduction to the Django one-to-many relationships In a one-to-many relationship, a row in a table is associated with one or more rows in another table. For example, a department may have one or more employees and each employee belongs to one department. The relationship between departments and employees is aContinue Reading

Introduction to the Django One-To-One relationship The one-to-one relationship defines a link between two tables, where each row in a table appears once in another table. For example, each employee has a contact and each contact belongs to one employee. So the relationship between employees and contacts is a one-to-oneContinue Reading

Introduction to Django ORM ORM stands for object-relational mapping. ORM is a technique that allows you to manipulate data in a relational database using object-oriented programming. Django ORM allows you to use the same Python API to interact with various relational databases including PostgreSQL, MySQL, Oracle, and SQLite. Django ORMContinue Reading