Commit 5999e1a6 authored by Lance Cedric Tan's avatar Lance Cedric Tan

Accomplished Homepage app

parent 34ee46d3
No preview for this file type
# Generated by Django 3.2 on 2023-02-16 12:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Album',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('album_name', models.CharField(max_length=255)),
('description', models.CharField(max_length=255)),
('release_date', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Artist',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('artist_name', models.CharField(max_length=255)),
('monthly_listeners', models.IntegerField()),
],
),
migrations.CreateModel(
name='SongInfo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('song_title', models.CharField(max_length=255)),
('song_length', models.IntegerField()),
('album', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Homepage.album')),
('artist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Homepage.artist')),
],
),
migrations.AddField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Homepage.artist'),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
from django.db import models
from django.urls import reverse
class Artist(models.Model):
artist_name = models.CharField(max_length=255)
monthly_listeners = models.IntegerField()
def __str__(self):
return artist_name
def get_absolute_url(self):
return reverse('artist', args=[str(self.artist_name)])
class Album(models.Model):
album_name = models.CharField(max_length=255)
artist = models.ForeignKey(
Artist,
on_delete=models.CASCADE
)
description = models.CharField(max_length=255)
release_date = models.CharField(max_length=255)
def __str__(self):
return album_name
def get_absolute_url(self):
return reverse('album', args=[str(self.album_name)])
class SongInfo(models.Model):
song_title = models.CharField(max_length=255)
artist = models.ForeignKey(
Artist,
on_delete=models.CASCADE
)
album = models.ForeignKey(
Album,
on_delete=models.CASCADE
)
song_length = models.IntegerField()
def __str__(self):
return song_title
def get_absolute_url(self):
return reverse('song', args=[str(self.song_title)])
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name= "Homepage"
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Welcome to Lance's Music Library")
File added
...@@ -43,6 +43,7 @@ INSTALLED_APPS = [ ...@@ -43,6 +43,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'Homepage',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('Homepage', include('Homepage.urls', namespace="Homepage")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
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