album_title="Ignite the night", genre="Rock", album_logo= "http://schmoesknow.com/wp-content/uploads/2017/05/Wonder-Woman-Movie-Artwork.jpg" ) # above code is all on one line ## a.save() # writes into the database ## a.id # show the ID (primary key) # Add "Albums" and "Song" table entries: Rick Astley # from music.models import Album, Song a = Album( artist="Rick Astley", album_title="Whenever You Need Somebody", genre="rock", album_logo= "https://www.cs.allegheny.edu/sites/obonhamcarter/cs312/graphics/rick.jpg" ) #Above line: all on one line a.save() # # add a song for the album s = Song() s.album_id = 2 s.Album = "Whenever You Need Somebody" s.song_title = "Never Gonna Give You Up" s.file_type = "mp3" s.save()
from music.models import Album,Song album1.song_set.all() album1 = Album.objects.get(pk=1) album1.artist song = Song() song.album = album1 song.file_type = 'mp3' song.song_title = 'I love my boyfirend' song.save() album1.song_set.all() album1.song_set.create(song_title = 'I love bacon',file_type = 'mp3') album1.song_set.create(song_title = 'Bucky is Lucky',file_type = 'mp3') album1.song_set.create(song_title = 'Ice Cream',file_type = 'mp3') song = album1.song_set.create(song_title = 'Ice Cream',file_type = 'mp3') song.album song.song_title album1.song_set.all() album1.song_set.count() %hist -f CreateSong2.py
from music.models import Album,Song album1 = Album.objects.get(pk=1) album1.artist song = Song() song.album = album1 song.file_type = "mp3" song.song_title = "I hate my boyfirend" song.save() %his -f AddSong.py %hist -f AddSong.py