Commit 02335701 authored by Lay Villanueva's avatar Lay Villanueva

added function in models.py

added get_absolute_url per class
parent d4e0f84b
Pipeline #2740 failed with stages
...@@ -8,6 +8,9 @@ class Artist(models.Model): ...@@ -8,6 +8,9 @@ class Artist(models.Model):
def __str__(self): def __str__(self):
return '{} - {} monthly listeners'.format(self.artist_name,self.monthly_listeners) return '{} - {} monthly listeners'.format(self.artist_name,self.monthly_listeners)
def get_absolute_url(self):
return reverse('artist_detail', args=[str(self.artist_name)])
class Album(models.Model): class Album(models.Model):
album_name = models.CharField(max_length=255) album_name = models.CharField(max_length=255)
...@@ -19,6 +22,9 @@ class Album(models.Model): ...@@ -19,6 +22,9 @@ class Album(models.Model):
return '{} by {} released on {} is {}'.format(self.album_name,self.artist, return '{} by {} released on {} is {}'.format(self.album_name,self.artist,
self.release_date,self.description) self.release_date,self.description)
def get_absolute_url(self):
return reverse('album_detail', args=[str(self.album_name)])
class Song(models.Model): class Song(models.Model):
song_title = models.CharField(max_length=255) song_title = models.CharField(max_length=255)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE) artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
...@@ -28,3 +34,6 @@ class Song(models.Model): ...@@ -28,3 +34,6 @@ class Song(models.Model):
def __str__(self): def __str__(self):
return '{} by {} from {} is {} long.'.format(self.song_title,self.artist, return '{} by {} from {} is {} long.'.format(self.song_title,self.artist,
self.album,self.song_length) self.album,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