This is my reference notes

python -m django –version

django-admin startproject mysite

python manage.py runserver

Project
Apps
-Views – Controller – Model Validation on the server side
-Templates – Views (Models Validation on the Client Side) – Javascript disabled – Submit
-Settings.py add the following connection string as default.
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘northwind’,
‘USER’: ‘developer’,
‘PASSWORD’: ‘Kingdom’,
‘HOST’: ‘127.0.0.1’,
‘PORT’: ‘3306’,
},
-Run this command to install the mysql client globally using pip.
pip install mysqlclient
Admin App
-Register all models in the Admin app.
-Master data entry should be done via App.
-All master data tables must start with ref_

Models
    -Foreign key relationships must be maintained
    -Migrations must be used so that db deployment is done in correct steps as per the dependency.
    -Models additional validation must be done via validators https://docs.djangoproject.com/en/3.1/ref/validators/

Deployment
Production deployment must have a new secret key in the project’s settings.py
Project’s url.py should have the url entries for all applications otherwise we will get 404.

After the project is created run the following command and see the default homepage at this location.
python manage.py runserver

http://127.0.0.1:8000/

Step2 : Admin site setup and users management

Before creating any apps migrate admin models to database using the following command.
python manage.py migrate
Create a superuser using the following command.
python manage.py createsuperuser
Run the following query against the auth_user table to see if the superadmin is created successfully
SELECT * FROM djangotutorial.auth_user;
NOTE: After deployment to production. Ask the client to change password for the superadmin via admin app. **
Login to admin portal and enter first name and last name of the super admin if you want.
Create all the roles needed for your applications in the admin portal.
Grant required permission to all roles

Give additional permissions to users in addition to roles permissions

App Creation and Models Creation and Data Entry for Ref tables.

Create an app under this project using the following command.
python manage.py startapp cruddemo
Add urls.py to the app folder and initialize the app name as shown below
from . import views
from django.urls import path
app_name = ‘cruddemo’
Create a sample table ref_record_status in Mysql and run the following command to generate python model class.
python manage.py inspectdb > output.txt
Copy only the models that your application needs from the output.txt file to models.py in your app.
Register the model in the admin portal.
in admin.py of the app add the following lines. Copy the model name from models.py file.
from .models import RefRecordStatus
admin.site.register(RefRecordStatus)
In project settings.py add the following entry in INSTALLED_APPS
‘cruddemo.apps.CruddemoConfig’,
Run the following command and login to the admin portal.
Add data to the reference tables via GUI.
TODO: Generate python code for migrating initial data also. **

Step 4: Deploying the database objects from admin and app to new database.

  1. Create a new database and update the name of the database in default connection string.
  2. Run this command to migrate all the admin objects.
    python manage.py migrate
  3. To migrate the objects of the applications run the following command.
    python manage.py makemigrations cruddemo
    python manage.py sqlmigrate cruddemo 0001
    python manage.py migrate

This did not work. **We need to solve it in the future.