This video covers Part 2: Models and the Admin site from section “Getting Started” of the Django Documentation.

TIMESTAMPS

00:00:00 – Intro

VS Code modification

00:00:39 – Fixing problems in VS Code
From my previous video (Part 1), you may notice several “small numbers” beside some items in the drop down menu at the left side of the screen. If you point the mouse to those “small numbers”, a popup message will say something like “problem found”.

So here we will solve those “problems”. But what are these problems? VS Code by default uses Python Interpreter from the system (global setting). However, our web app is build from within “dj4begin” virtual environment. Therefore VS Code with its usage of the system Python Interpreter will lack of some packages and dependencies that we install into “dj4begin” only.

00:03:49 – Terminal setting for VS Code
VS Code comes with its integrated Terminal that use either PowerShell and/or Command Prompt. It’s convenience. And for our tutorial we will set this Terminal to use Command Prompt with “dj4begin” virtual environment activated.

Setup Database for our Polls app

00:05:55 – Database setup

00:11:15 – TIME_ZONE setting
You may pick & set the appropriate Time Zone at this step, use data from the following link:
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

00:13:25 – INSTALLED_APPS setting
mysite/settings.py file contains a list of declared apps that are installed with the project “mysite”. All installed, created, and activated apps shall be included within the INSTALLED_APPS section of this file.

00:14:50 – “migrate” command
The full command is: “python manage.py migrate”. This will create and/or update the project’s database.

Tools to use with SQLite database

00:19:25 – Database command-line client
If you are a hardcore fan of command line practices, go here: https://www.sqlite.org/cli.html. With the sqlite3 command-line shell you can manipulate your SQLite database using command lines.

00:20:26 – DB Browser for SQLite
If you are looking for a more “visual” user interface, go for: https://sqlitebrowser.org. This is an interesting and easy to use desktop application that helps you manage your SQLite database.

django Models

00:23:00 – Create Models
This step is to create our first 2 models, the Question Model and the Choice Model.

Create tables and update the database

00:32:29 – “makemigrations” command
The complete command is: “python manage.py makemigrations polls”. Python commands are easy to comprehend, that command there will do something for the “polls” app. The thing it will do is a preparation to later “migrate” (create/update) the database.

00:35:35 – “sqlmigrate” command
Using this command actually will not “migrate” anything yet. It’s just help administrators to see what SQL django will do and they may adjust the scripts as such. Full command for our project: “python manage.py sqlmigrate polls 0001”.

00:39:39 – “check” command
The name said it, checking for problems if any. “python manage.py check”.

00:40:13 – run “migrate” to update database
“python manage.py migrate” will create and update your database on any changes we have done.

django free API

00:43:29 – Playing with the API
At this stage you will play with the free API of django. It’s useful and fun to get to know a bit of this API (Application Programming Interface) by manipulating with data of the “mysite” project.

Adding some Methods

00:50:00 – __str__() method

00:51:57 – Add a custom method to the Model

django Admin site

01:03:13 – Introducing the Django Admin
As I mentioned several times from the beginning of the video series, Django’s Admin Site is superb! Of course it’s my opinion only, whether it’s that helpful and convenient is for you to judge.

01:05:00 – Creating an admin user

01:07:13 – Start the development server

01:12:05 – Add “polls” app to admin site

01:13:51 – Explore the admin functionality

Thank you

01:18:00 – Thanks and see you in the next video

More on topic “Django Documentation, Getting Started”

This series can be found on: https://viws.net/category/django4beginners/
You may go to my YouTube Channel for more videos: https://www.youtube.com/channel/UC6JVvyI4k6zzh9vJNhRClRw

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *