Created admin displays, search fields, and filters

parent fec47881
...@@ -5,8 +5,27 @@ from .models import Artist, Album, Song ...@@ -5,8 +5,27 @@ from .models import Artist, Album, Song
class ArtistAdmin(admin.ModelAdmin): class ArtistAdmin(admin.ModelAdmin):
model = Artist model = Artist
list_display = ('artist_name', 'birth_name', 'monthly_listeners',)
search_fields = ('artist_name', 'birth_name',)
list_filter = ('artist_name', 'birth_name',)
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
model = Album model = Album
list_display = ('album_name', 'description', 'release_date', 'label', 'song_count',)
search_fields = ('album_name', 'description', 'label',)
list_filter = ('album_name',)
class SongAdmin(admin.ModelAdmin): class SongAdmin(admin.ModelAdmin):
model = Song model = Song
list_display = ('song_title', 'lyrics',)
search_fields = ('song_title', 'lyrics',)
list_filter = ('song_title',)
admin.site.register(Artist, ArtistAdmin)
admin.site.register(Album, AlbumAdmin)
admin.site.register(Song, SongAdmin)
# Generated by Django 4.1.6 on 2023-02-20 12:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='album',
name='label',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='album',
name='song_count',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='artist',
name='bio',
field=models.TextField(blank=True, max_length=700, null=True),
),
migrations.AddField(
model_name='artist',
name='birth_name',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='song',
name='lyrics',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='song',
name='music_video',
field=models.BooleanField(blank=True, null=True),
),
]
...@@ -5,8 +5,8 @@ from django.urls import reverse ...@@ -5,8 +5,8 @@ from django.urls import reverse
class Artist(models.Model): class Artist(models.Model):
artist_name = models.CharField(max_length=100) artist_name = models.CharField(max_length=100)
monthly_listeners = models.IntegerField() monthly_listeners = models.IntegerField()
birth_name = models.CharField(max_length=100) birth_name = models.CharField(max_length=100, blank=True, null=True)
bio = models.TextField(max_length=700) bio = models.TextField(max_length=700, blank=True, null=True)
def __str__(self): def __str__(self):
return '{}'.format(self.artist_name) return '{}'.format(self.artist_name)
...@@ -20,8 +20,8 @@ class Album(models.Model): ...@@ -20,8 +20,8 @@ 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=300) description = models.CharField(max_length=300)
release_date = models.DateField() release_date = models.DateField()
label = models.CharField(max_length=100) label = models.CharField(max_length=100, blank=True, null=True)
song_count = models.IntegerField() song_count = models.IntegerField(blank=True, null=True)
def __str__(self): def __str__(self):
return '{}'.format(self.album_name) return '{}'.format(self.album_name)
...@@ -35,8 +35,8 @@ class Song(models.Model): ...@@ -35,8 +35,8 @@ class Song(models.Model):
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()
music_video = models.BooleanField() music_video = models.BooleanField(blank=True, null=True)
lyrics = models.TextField() lyrics = models.TextField(blank=True, null=True)
def __str__(self): def __str__(self):
return '{}'.format(self.song_title) return '{}'.format(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