コード例 #1
0
from music.models import Ablum, Song
from music.models import Album, Song
Album.objects.all()
a = Album(artist='Taylor Swift',album_title='Red',genre='Country',album_logo="https://imgchr.com/i/Kb9vFO")
a.save()
a.artist
a.album_title
a.id
a.pk
b = Album()
b.artist = "Myth"
b.album_title = "High School"
b.genre = "Punk"
b.album_logo = ""
b.album_logo = ""
b.album_logo = "https://imgchr.com/i/KbC100"
b.saz
b.save()
a.artist
b.artist
b.album_title = "Middle School"
b.album_title
Album.objects.all()
%hist -f Create_Albums.py
コード例 #2
0
#different ways of adding rows in the table
from music.models import Album ,Song
Album.objects.all()

a = Album(artist = "Taylor Swift", album_title = "Red",genre = "Country" ,album_logo = "https://upload.wikimedia.org/wikipedia
a.save()

b=Album()
b.artist = "One direction"
b.album_title = "once a day"
b.genre = "punk"
b.album_logo = "http://cdn01.cdn.justjared.com/wp-content/uploads/2014/02/stewart-whoa/kristen-stewart-if-i-do-a-good-scene-i-say-whoa-thats-dope-01.jpg"
b.save()

Album.objects.all()
Album.objects.filter(id =1)
#prints the first one
Album.objects.filter(artist__startswith='Taylor')


#adding songs to database

In [1]: from music.models import Album,Song

In [2]: album1 = Album.objects.get(pk = 1)

In [3]: album1.artist
Out[3]: 'Taylor Swift'

In [4]: song = Song()