Esempio n. 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
Esempio n. 2
0
#operation on the python manage.py shell.insert/update db.
$python manage.py shell
from music.models import Album, Song

Album.objects.all()
a = Album(artist="Taylor Swift", album_title="Red",genre="country",album_logo="asdfsdsfa")
a.save()
a.artist
a.id
a.pk #a.id or a.pk -primary key
#second way to input values to db
b=Album()
b.artist= "Myth"
b.album_title="High school"
b.album_logo="/home/local/ANT/kendavar/kendavar/"
b.save()
Album.objects.all()

#dunter/string representaion of the object.It gives a name to the object
class Album(models.Model):
    artist = models.CharField(max_length=250)
    album_title = models.CharField(max_length=500)
    genre = models.CharField(max_length=100)
    album_logo = models.CharField(max_length=1000)

    def __str__(self):                                     #This will give the name to the object when we call Album.objects.all()
        return self.album_title + "_" + self.artist

#filter with id
Album.objects.filter(id=2)
Esempio n. 3
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()