Django Crash Course by Dennis Ivy

1. Project Setup

Link

Useful Commands

  1. django-admin : check if django is installed correctly
  2. django-admin startproject : create a django project
  3. python3 manage.py runserver : run the project on Port 8000
  4. python3 manage.py startapp : create an app in the project file
  5. python manage.py createsuperuser : create an admin user
  6. pip install django-cors-headers : install cors headers

Basic Project File Structure

  1. manage.py - don't tocuh this file. Gives list of commands we'll use
  2. wsgi.py - web serveer files
  3. urls.py - a url routing system. we'll add a list of paths
  4. settings.py - the main configurations to your django project

Useful Commands & Steps

  1. python3 manage.py startproject crm - create the django project
  2. python3 manage.py startapp accounts - create an application within the prject called accounts
  3. Register the app in the project in settings.py

Basic App File Structure Key Files

  1. admin.py
  2. models.py
  3. views.py

2. URLs and Views

Link

urls_views.png

Setps done

  1. Create a urls.py file in accounts app
  2. Create views functions in views.py
  3. Link views.py funcions to app urls.py
  4. Link app urls.py to projects.py

3. Templates & Inheritance

Link

  • Django specifically looks for :
    --- app
    -----templates
    ------app
    -------your html files

!!!note Be sure to name the folder templates; that's what django looks for

  • We build the templates/accounts files

4. Static Files & Images

Link

  • Note media urls and static urls in settings.py
  • Also note statict folder and how we import static iles into html templates *{% load static %}

5. Database Models & Admin Panel

Link

  • Created http://127.0.0.1:8000/admin/auth/user/

  • Models : models.png

  • Worked on models.py

  • python3 manage.py makemigrations & python3 manage.py migrate - the command used to create a model in models.py in the databse

  • Remember to register your models in admin.py

6. Database Relationships | One To Many & Many to Many

Link

One to Many Relationship

  • An Example : One Customer has placed 3 different orders

one-to_many.png

Many to Many Relationship

  • An Example : A tag can have many products and a product can also have many tags.

many_to_many.png

  • We added dummy data at this stage

7. Database Model Queries

Link

query.png

  • We work from an interactive console accesed by inputing the command python3 manage.py shell
  • Query CheatSheet

8. Rendering Data to Templates | Template Tags

Link

  • Worked on creating the variables that hold query results in views.py
  • Also linked the value of these variables and input them in the respective html files

9 & 10. Dynamic URL Routing & Templates

9 - Link
10 - Link

  • We worked on the urls.py files as well as updating the href links for a tags across the templates and the
  • str:pk : string : primary key

11. Create Update & Delete (CRUD) with Model Forms

Link

  • {% csrf_token %} is a way of passing our data securely
  • Note the update and delte order forms in templates and views.py

12. Inline Formsets

Link

  • Inline formsets are used to create multile forms within one form.
  • {{ form.management_form }} - sends data for each individual form in the formset.

13. Filter Form Table Search

Link

  • Reference djngo filter package
  • icontains means be case insensitive in the filter

14. User Registration and Login Authentication

Link

  • Would be wise to create an auth_view.py for auth view functions

15. User Role Based Permissions & Authentication

Link


References