Commit e39941fd authored by Mariam Garsin's avatar Mariam Garsin

Modified homepage

parent 6a559e4f
from django.contrib import admin from django.contrib import admin
# Register your models here. from .models import Artist, Album, Song
class ArtistAdmin(admin.ModelAdmin):
model = Artist
class AlbumAdmin(admin.ModelAdmin):
model = Album
class SongAdmin(admin.ModelAdmin):
model = Song
admin.site.register(Artist, ArtistAdmin)
admin.site.register(Album, AlbumAdmin)
admin.site.register(Song, SongAdmin)
\ No newline at end of file
# Generated by Django 4.2 on 2023-04-18 08:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='album',
name='label',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='album',
name='song_count',
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name='artist',
name='bio',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='artist',
name='birth_name',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='song',
name='lyrics',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='song',
name='music_video',
field=models.BooleanField(null=True),
),
]
# Generated by Django 4.2 on 2023-04-19 06:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_album_label_album_song_count_artist_bio_and_more'),
]
operations = [
migrations.AlterField(
model_name='album',
name='release_date',
field=models.DateTimeField(),
),
]
from django.db import models from django.db import models
from django.utils import timezone
class Artist(models.Model): class Artist(models.Model):
artist_name = models.TextField() artist_name = models.TextField()
birth_name = models.TextField(blank=True)
monthly_listeners = models.IntegerField() monthly_listeners = models.IntegerField()
bio = models.TextField(blank=True)
def __str__(self): def __str__(self):
return '{}, {}'.format(self.artist_name, self.monthly_listeners) return '{} [{}]'.format(self.artist_name, self.birth_name)
class Album(models.Model): class Album(models.Model):
album_name = models.TextField() album_name = models.TextField()
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
description = models.TextField() description = models.TextField()
release_date = models.IntegerField() artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
release_date = models.DateTimeField()
label = models.TextField(blank=True)
song_count = models.IntegerField(null=True)
def __str__(self): def __str__(self):
return '{}, {} {} {}'.format(self.album_name, self.artist, self.description, self.release_date) return '{} [{}], {} {}'.format(self.album_name, self.release_date, self.description, self.label)
class Song(models.Model): class Song(models.Model):
song_title = models.TextField() song_title = models.TextField()
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.FloatField() song_length = models.FloatField()
music_video = models.BooleanField(null=True)
lyrics = models.TextField(blank=True)
def __str__(self): def __str__(self):
return '{}, {} {} {}'.format(self.song_title, self.artist, self.album, self.album) return '{}'.format(self.song_title)
from django.contrib import admin
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'),
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from.models import Artist, Album, Song
def index(request): def index(request):
return HttpResponse('Welcome to Yam’s Music Library!') page_content="""<H1>Welcome to Yam’s Music Library!</H1>"""
\ No newline at end of file for album in Album.objects.all():
newAlbumDateTime = album.release_date.strftime("%m-%d-%Y %I:%M %p")
page_content += """<ul>
<li>Date and Time: {}<br>
<li>Artist: {}<br>
<li>Album Name: {}<br>
</ul>""".format(newAlbumDateTime, album.artist.artist_name,
album.album_name)
for song in Song.objects.filter(album=album):
page_content += f"<li>{song.song_title}</li>"
page_content += "</ul></li></ul>"
return HttpResponse(page_content)
\ No newline at end of file
...@@ -41,9 +41,9 @@ INSTALLED_APPS = [ ...@@ -41,9 +41,9 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'homepage',
'about', 'about',
'contact', 'contact',
'homepage',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
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