Commit 31d64f33 authored by Alliyah Marcelo's avatar Alliyah Marcelo

Configured models to better visualize them in Django Admin.

parent fb7c8c6b
...@@ -3,16 +3,30 @@ from django.contrib import admin ...@@ -3,16 +3,30 @@ from django.contrib import admin
from .models import Artist, Album, Song from .models import Artist, Album, Song
class AlbumInline(admin.TabularInline):
model = Album
class SongInline(admin.TabularInline):
model = Song
class ArtistAdmin(admin.ModelAdmin): class ArtistAdmin(admin.ModelAdmin):
model = Artist model = Artist
list_display = ( list_display = ('artist_name', 'birth_name', 'monthly_listeners',)
'artist_name',
'birth_name',
'monthly_listeners',
)
search_fields = ('artist_name', 'birth_name',) search_fields = ('artist_name', 'birth_name',)
list_filter = ('artist_name', 'birth_name',) list_filter = ('artist_name', 'birth_name',)
inlines = [AlbumInline, SongInline,]
fieldsets = [
('Artist Data', {
'fields':[
('artist_name', 'birth_name'), 'monthly_listeners'
]
}),
]
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
model = Album model = Album
...@@ -38,7 +52,7 @@ class SongAdmin(admin.ModelAdmin): ...@@ -38,7 +52,7 @@ class SongAdmin(admin.ModelAdmin):
search_fields = ('song_title', 'lyrics',) search_fields = ('song_title', 'lyrics',)
list_filter = ('song_title',) list_filter = ('song_title',)
# Register your models here. # Register your models here.
admin.site.register(Artist, ArtistAdmin) admin.site.register(Artist, ArtistAdmin)
admin.site.register(Album, AlbumAdmin) admin.site.register(Album, AlbumAdmin)
......
# Generated by Django 3.2 on 2023-02-21 06:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_alter_song_album'),
]
operations = [
migrations.AddField(
model_name='album',
name='label',
field=models.CharField(blank=True, max_length=50),
),
migrations.AddField(
model_name='album',
name='song_count',
field=models.IntegerField(default='0000000'),
),
migrations.AddField(
model_name='artist',
name='bio',
field=models.CharField(blank=True, max_length=700),
),
migrations.AddField(
model_name='artist',
name='birth_name',
field=models.CharField(blank=True, max_length=50),
),
migrations.AddField(
model_name='song',
name='lyrics',
field=models.CharField(blank=True, max_length=8000),
),
migrations.AddField(
model_name='song',
name='music_video',
field=models.BooleanField(default=True),
),
]
# Generated by Django 3.2 on 2023-02-21 06:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0007_auto_20230221_1408'),
]
operations = [
migrations.AlterField(
model_name='song',
name='music_video',
field=models.BooleanField(default=None),
),
]
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Artist(models.Model): class Artist(models.Model):
artist_name = models.CharField(max_length=50) artist_name = models.CharField(max_length=50)
monthly_listeners = models.IntegerField() monthly_listeners = models.IntegerField()
birth_name = models.CharField(max_length=50) birth_name = models.CharField(max_length=50, blank=True)
bio = models.CharField(max_length=700) bio = models.CharField(max_length=700, blank=True)
def __str__(self):
return '{}: {}'.format(self.artist_name, self.birth_name)
#def get_absolute_url(self):
#return reverse(admin('artist_detail', args=[str(self.artist_name)]))
@property
def is_tutorial(self):
return self.monthly_listeners == 1
class Album(models.Model): class Album(models.Model):
...@@ -17,8 +29,18 @@ class Album(models.Model): ...@@ -17,8 +29,18 @@ class Album(models.Model):
) )
description = models.CharField(max_length=1000) description = models.CharField(max_length=1000)
release_date = models.CharField(max_length=50) release_date = models.CharField(max_length=50)
label = models.CharField(max_length=50) label = models.CharField(max_length=50, blank=True)
song_count = models.IntegerField() song_count = models.IntegerField(default='0000000')
def __str__(self):
return '{}'.format(self.album_name)
#def get_absolute_url(self):
#return reverse(admin('artist_detail', args=[str(self.artist_name)]))
@property
def is_tutorial(self):
return self.song_count == 1
class Song(models.Model): class Song(models.Model):
...@@ -34,5 +56,11 @@ class Song(models.Model): ...@@ -34,5 +56,11 @@ class Song(models.Model):
related_name='song_album' related_name='song_album'
) )
song_length = models.IntegerField() song_length = models.IntegerField()
music_video = models.BooleanField() music_video = models.BooleanField(default=None)
lyrics = models.CharField(max_length=8000) lyrics = models.CharField(max_length=8000, blank=True)
def __str__(self):
return '{} ({})'.format(self.song_title, self.song_length)
#def get_absolute_url(self):
#return reverse(admin('artist_detail', args=[str(self.artist_name)]))
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