from django.db import models
class Album(models.Model):
artist = models.CharField(max_length=50)
album_title = models.CharField(max_length=50)
genre = models.CharField(max_length=50)
album_logo = models.CharField(max_length=500)
def __str__(self):
return self.album_title + ' - ' + self.artist
class Song(models.Model):
album = models.ForeignKey(Album, on_delete=models.CASCADE)
file_type = models.CharField(max_length=50)
song_title = models.CharField(max_length=50)
python manage.py shell
exit()
from music.models import Album, Song
Album.objects.all()
<QuerySet [<Album: Red - Taylor Swift>, <Album: High School - Myth>]>
Album.objects.filter(id=1)
<QuerySet [<Album: Red - Taylor Swift>]>
Album.objects.filter(id=3)
<QuerySet []>
Album .objects.filter(artist__startswith='Taylor')
<QuerySet [<Album: Red - Taylor Swift>]>
No comments:
Post a Comment