Updated string representaion of homepage app models.

parent 1f633198
from django.db import models
from django.urls import reverse
# Create your models here
class Artist(models.Model):
artist_name = models.CharField(max_length=100)
monthly_listeners = models.IntegerField()
def __str__(self):
return '{}'.format(self.artist_name)
return '{} with {} monthly listeners'.format(self.artist_name, self.monthly_listeners)
def get_absolute_url(self):
return reverse('artist_detail', args=[str(self.artist_name)])
......@@ -19,11 +20,13 @@ class Album(models.Model):
release_date = models.DateField()
def __str__(self):
return '{} by {}'.format(self.album_name, self.artist)
return '{} by {} released on {}. {}'.format(self.album_name, self.artist
,self.release_date,self.description)
def get_absolute_url(self):
return reverse('album_detail', args=[str(self.album_name)])
class Song(models.Model):
song_title = models.CharField(max_length=100)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
......@@ -31,7 +34,8 @@ class Song(models.Model):
song_length = models.DurationField()
def __str__(self):
return '{} from {} by {}'.format(self.song_title, self.album, self.artist)
return '{} from {} by {} is {} long'.format(self.song_title, self.album,
self.artist, self.song_length)
def get_absolute_url(self):
return reverse('song_detail', args=[str(self.song_title)])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment