Tuesday, 18 August 2015
Day 6 - updating database
First run Django Management Console it is Django shell in Visual Studio
right clic on your project "Batabaze2" choose "Python" and choose "open django shell"
1. import module Artist
from app.models import Artist
2. newArtist = Artist(name='Ralf Rengo', year_formed=2002)
3. newArtist.save()
To make changes:
>>> newArtist.year_formed = 2000
>>> newArtist.save() # REMEMBER TO SAVE!
At the end:
5. allArtists= Artist.objects.all()
To see if the record is in database write:
>>> allArtists[0].name
To see all records:
for artist in allArtists:
... print(artist.id, artist.name, artist.year_formed)
To add data to Albums just write command:
alb2 = Album(name='Hih Hom Ham', artist =a2)
# the album will be automatically connected to Artist a2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment