Control Statements in C: Control Statements are the statements that alter the flow of execution and provide better control to the programmer on the flow of execution. They are useful to write better and more complex programs. A program executes from top to bottom except when we use control statements,Continue Reading

Introduction to Django sessions Django has a session framework that supports both anonymous and user sessions. Django uses the session middleware to send and receive cookies. The following picture illustrates how the Django sessions work: When a web browser makes the first HTTP request to the web server, the sessionContinue Reading

Introduction to HTTP cookies When a web server interacts with many different browsers at the same time, it needs to identify which browser a specific request came from. Because the HTTP request/response is stateless, all web browsers look identical. To identify the web browsers, the web server uses cookies. Technically,Continue Reading

Introduction to the Django Group By The SQL GROUP BY clause groups the rows returned by a query into groups. Typically, you use aggregate functions like count, min, max, avg, and sum with the GROUP BY clause to return an aggregated value for each group. Here’s the basic usage of the GROUP BY clause in a SELECT statement: SELECT column_1, AGGREGATE(column_2)Continue Reading

Preparing data We’ll use the Employee and Department models from the hr application for the demonstration. The Employee and Department models map to the hr_employee and hr_department tables: First, add the salary field to the Employee model: class Employee(models.Model): salary = models.DecimalField(max_digits=15, decimal_places=2) # …Code language: Python (python) Second, make migrations using the makemigrations command: python makemigrationsCode language: Python (python) Output: Migrations for ‘hr’: hr\migrations\ – Add field salary to employeeCodeContinue Reading

Introduction to the Django QuerySet exists() method Sometimes, you want to check if a query contains any rows. To do it, you use the exists() method of the QuerySet object. The exists() method returns True if the QuerySet contains any rows or False otherwise. Behind the scenes, the exists() will attempt to perform the query in the fastest way possible. However, the query willContinue Reading

Introduction to Django isnull We’ll use the Employee and Contact models from the HR application for the demonstration. The Emloyee and Contact models map to the hr_employee and hr_contact tables: In relational databases, NULL denotes missing information. For example, if you don’t know the contact of an employee, you can use NULL for the contact of the employee at the time of recording. NULL is special because you cannotContinue Reading

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