Commit d633f74a authored by Joei Yucoco's avatar Joei Yucoco

Changed some field types and cleaned up the admin and models code a bit

parent 7f044ac2
from django.contrib import admin
from .models import Artist, Album, Song
class AlbumInline(admin.TabularInline):
model = Album
class SongInline(admin.TabularInline):
model = Song
class ArtistAdmin(admin.ModelAdmin):
model = Artist
search_fields = ('artist_name', 'birth_name',)
list_display = ('artist_name', 'birth_name','monthly_listeners',)
list_filter = ('artist_name', 'birth_name',)
inlines = [SongInline, AlbumInline]
class AlbumAdmin(admin.ModelAdmin):
model = Album
search_fields = ('album_name', 'description','label',)
list_display = ('album_name', 'description','release_date','label', 'song_count',)
list_filter = ('album_name',)
inlines = [SongInline, ]
class SongAdmin(admin.ModelAdmin):
model = Song
search_fields = ('song_title', 'lyrics',)
list_display = ('song_title', 'song_length', 'lyrics', 'music_video',)
list_filter = ('song_title',)
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin.site.register(Artist, ArtistAdmin)
admin.site.register(Album, AlbumAdmin)
admin.site.register(Song, SongAdmin)
......
# Generated by Django 3.2 on 2023-02-21 03:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Homepage', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='artist',
name='bio',
field=models.TextField(),
),
migrations.AlterField(
model_name='artist',
name='birth_name',
field=models.CharField(max_length=100),
),
]
......@@ -3,8 +3,10 @@ from django.db import models
class Artist(models.Model):
artist_name = models.CharField(max_length=100)
monthly_listeners = models.IntegerField()
birth_name = models.TextField()
bio = models.CharField(max_length=700)
birth_name = models.CharField(max_length=100)
bio = models.TextField()
class Album (models.Model):
album_name = models.CharField(max_length=100)
......@@ -14,6 +16,8 @@ class Album (models.Model):
label = models.CharField(max_length=100)
song_count = models.IntegerField()
class Song (models.Model):
song_title = models.CharField(max_length=100)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
......
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