Home

Awesome

learning-django

Learning Django from YouTube

Just one of the things I'm learning. https://github.com/hchiam/learning

My older repo: https://github.com/hchiam/djangoApp

Boilerplate code: https://github.com/hchiam/Django-REST-Boilerplate

What's next are my notes from following thenewboston's YouTube tutorial series:

get django

create project "website"

create "app"

connect/synchronize database

create & activate models (how you want to store your data; tables and columns)

Remember 3 steps when you want to udpate changes to databases:

  1. change website/models.py
  2. python manage.py makemigrations app1
  3. python manage.py migrate

database API

from app1.models import Album, Song
Album.objects.all()
a = Album(artist="the new boston", album_title="Red", genre="Country", album_logo="https://thenewboston.com/photos/users/2/original/e1ee187e9e0225ba124ba1c7c9dbfa56.png")
a.save()
a.artist
a.album_title
a.id # this is the same
a.pk # as this
b = Album()
b.artist = "artist2"
b.album_title = 'title2'
b.genre = 'Jazz'
b.album_logo = 'https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2@2x.png'
b.save()
a.artist
b.artist
b.album_title = "High School"
b.album_title
exit()

filtering database results (video #10)

first, set up so filtered results show basic info

actually do the filtering

admin interface

create another view

connect request/response to database

create template

shortcut for load-render template

activate 404 HTTP error page + message

add entries to database

and then create song, set attributes, and save it:

python manage.py shell
from app1.models import Album, Song
album1 = Album.objects.get(id=5)
album1.artist # should return 'the new boston'
song = Song() # requires album, file_type, song_title
song.album = album1
song.file_type = 'mp3'
song.song_title = 'some title'
song.save()

oooor do that in one step with the create function:

(continuing with the same shell)

album1.song_set.all() # to see it so far
album1.song_set.create(song_title='I love bacon', file_type='mp3') # album already specified
album1.song_set.create(song_title='ice cream', file_type='mp3') # album already specified
song = album1.song_set.create(song_title='hamburger', file_type='mp3') # make use of returned reference to that song
song.album
song.song_title
album1.song_set.all() # to see all songs in album1
album1.song_set.count() # gets size of set

design the details.html template

remove hardcoded URLs (i.e. completely dynamic URLs)

namespaces / pattern reuse

HTTP 404 shortcut

create form (in the easiest way to understand anyways)

You might want to have a URL that doesn't link to a template, like a "logging out" page that runs and then automatically redirects to another page.

Actually make the form:

add style with static files

Example: https://github.com/buckyroberts/Viberr

add Bootstrap style

build up more of navigation menu

create base template (e.g. consistent navigation bar and styling)

generic views (to write less code with classes, instead of functions in views.py)

(before the model form tutorial videos 30-31)

https://github.com/Ananthu/Django-thenewboston-youTube-classes

model forms - CreateView part (videos 30-31)