Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Django IntroductionChapter 3. Django Models and Databases

Chapter 3. Django Models and Databases

Django Models and Databases Guide

This chapter covers how to create a database for Django applications. In the first few sections, we’ll explain the critical steps to create a database, and in the later part of this chapter, we’ll explain how to edit the models.py file in detail.

What We Cover in This Chapter

The following topics are covered in this chapter:

Create a Database in Django

In this section, we'll go over the essential steps to create a database in Django: defining models in the models.py file, creating migration files, and applying migrations to generate tables in the database.

Relational Database

We’ll explore relational databases and their key concepts, such as tables, fields, records, and relationships. We’ll also define the different types of relationships: one-to-many, one-to-one, and many-to-many.

Create Django Models

This section introduces how to define models in Django using Python classes. We’ll demonstrate how to define fields with different data types and options, including help text, choices, and relationships.

Makemigrations and Migrate

In this section, we'll cover the makemigrations and migrate commands, which allow you to create and apply database migrations in Django, ensuring that your database schema matches your models.

Add Models in Django Admin – admin.py

This section explains how to register your Django models in the Django admin panel, making them accessible for CRUD operations directly from the Django admin interface.

Change Display Name of Record Objects

We’ll learn how to customize the way records are displayed in the Django admin by using the __str__() method in the model definition.

Django Models – Data Field Type

Here, we'll introduce key data field types in Django models, including CharField, TextField, IntegerField, and others. We'll also explore their options and when to use each field type.

Django Models – Field Options

We’ll dive deeper into field options such as blank, unique, and default, which help define the behavior of each field in the database.

Django Models – Help Text Option

This section explains how to use the help_text option to provide guidance for users in the Django admin interface when entering data for each field.

Django Models – Choices Option

We’ll cover how to use the choices option in Django models to create a dropdown list of choices for a field, and how to display the selected choice in a human-readable format.

Django Models – DateField with datetime Module

In this section, we’ll learn how to use the DateField along with the datetime module to set date values in our models, along with options like auto_now_add and auto_now.

Django Models – Relationship Fields

This section covers how to establish relationships between Django models using ForeignKey, OneToOneField, and ManyToManyField.

Django Models – ID

We’ll explore how Django automatically adds an id field to models as a primary key and how to use it for defining relationships between models.

Django Models – ForeignKey (OneToMany Relationship)

This section explains how to create a one-to-many relationship using ForeignKey and configure the on_delete behavior for related models.

Django Models – OneToOneField

In this section, we’ll cover how to create a one-to-one relationship between models using OneToOneField and how to define the primary key for such relationships.

Django Models – ManyToManyField

We’ll learn how to define a many-to-many relationship between models using ManyToManyField, and Django’s automatic creation of an intermediary join table.

Learn offline for better focus!
A book for this course is available on Amazon.

Django Visual Guide

The Complete Beginner's Handbook to Mastering Web Development Effortlessly Without Prior Programming Experience

Your browser does not support the video tag.
Get the Book Now

More Topics to Explore

Overview of Django User Management Functions

Overview of User Management Functions

Managing Static Files in Django Production

Static File Settings

Setting Up SSH Remote Connection for Deployment

Hosting Service Initial Settings (2) – SSH Remote Connection

Overview of Django User Management Functions

Overview of User Management Functions

Managing Static Files in Django Production

Static File Settings

Setting Up SSH Remote Connection for Deployment

Hosting Service Initial Settings (2) – SSH Remote Connection

Tags:

Database

Django Models

Django Introduction
Course Content

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment