Updated models.py with additional attributes

Included additional attributes in each of the classes to provide more information such as birth name, bio, label, song count, etc.
parent 6cc0948e
from django.urls import path from django.urls import path
from .views import index from .views import index
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
] ]
......
# Generated by Django 4.1.6 on 2023-02-21 10:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_alter_artist_monthly_listeners'),
]
operations = [
migrations.AddField(
model_name='album',
name='label',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='album',
name='song_count',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='artist',
name='bio',
field=models.CharField(blank=True, max_length=700, null=True),
),
migrations.AddField(
model_name='artist',
name='birth_name',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='song',
name='lyrics',
field=models.CharField(blank=True, max_length=30000, null=True),
),
migrations.AddField(
model_name='song',
name='music_video',
field=models.BooleanField(choices=[(False, 'does not have'), (True, 'has')], default=False, verbose_name='Music Video?'),
),
]
# Generated by Django 4.1.6 on 2023-02-21 10:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_album_label_album_song_count_artist_bio_and_more'),
]
operations = [
migrations.AlterField(
model_name='song',
name='lyrics',
field=models.TextField(blank=True, null=True),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Artist(models.Model): class Artist(models.Model):
artist_name = models.CharField(max_length=255, unique=True) artist_name = models.CharField(max_length=255, unique=True)
monthly_listeners = models.IntegerField() monthly_listeners = models.IntegerField()
birth_name = models.CharField(max_length=255, blank=True, null=True)
bio = models.CharField(max_length=700, blank=True, null=True)
def __str__(self): def __str__(self):
return '{} - {} monthly listeners'.format(self.artist_name,self.monthly_listeners) return '{} - {} monthly listeners a.k.a {} is {}'.format(self.birth_name, self.monthly_listeners,
self.birth_name, self.bio)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('artist_detail', args=[str(self.artist_name)]) return reverse('artist_detail', args=[str(self.artist_name)])
...@@ -17,23 +21,30 @@ class Album(models.Model): ...@@ -17,23 +21,30 @@ class Album(models.Model):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE) artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
description = models.CharField(max_length=999) description = models.CharField(max_length=999)
release_date = models.DateField() release_date = models.DateField()
label = models.CharField(max_length=255, blank=True, null=True)
song_count = models.IntegerField(default=1)
def __str__(self): def __str__(self):
return '{} by {} released on {} is {}'.format(self.album_name,self.artist, return '{} by {} with {} songs released on {} under {} is {}'.format(self.album_name,self.artist,
self.release_date,self.description) self.song_count, self.release_date, self.label, self.description)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('album_detail', args=[str(self.album_name)]) return reverse('album_detail', args=[str(self.album_name)])
class Song(models.Model): class Song(models.Model):
isMusicVideo = [(False, 'does not have'),(True,'has')]
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)
album = models.ForeignKey(Album, on_delete=models.CASCADE) album = models.ForeignKey(Album, on_delete=models.CASCADE)
song_length = models.DurationField() song_length= models.DurationField(verbose_name="Song Length (in seconds)")
music_video = models.BooleanField(verbose_name="Music Video?", default=False, choices=isMusicVideo )
lyrics = models.TextField(blank=True, null=True)
def __str__(self): def __str__(self):
return '{} by {} from {} is {} long.'.format(self.song_title,self.artist, return '{} by {} from {} is {} long. It {} a music video. Lyrics can be found here: {}'.format(self.song_title,
self.album,self.song_length) self.artist, self.album,self.song_length, self.music_video, self.lyrics)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('song_detail', args=[str(self.song_title)]) 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