Update admin view on models

parent 653e3176
from django.contrib import admin from django.contrib import admin
from .models import Artist, Album, Song from .models import Artist, Album, Song
class ArtistAdmin(admin.ModelAdmin): class AlbumInline(admin.TabularInline):
model = Artist model = Album
list_display = ('artist_name', 'birth_name', 'monthly_listeners')
search_fields = ('artist_name', 'birth_name') class SongInline(admin.TabularInline):
model = Song
class ArtistAdmin(admin.ModelAdmin):
model = Artist
list_display = (
'artist_name',
'birth_name',
'monthly_listeners')
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', 'bio'
]
}),
]
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
model = Album model = Album
list_display = (
list_display = ('album_name', 'description', 'release_date', 'label', 'song_count') 'album_name',
'description',
'release_date',
'label', 'song_count')
search_fields = ('album_name', 'description', 'label') search_fields = ('album_name', 'description', 'label')
list_filter = ('album_name',)
list_filter = ('album_name', )
class SongAdmin(admin.ModelAdmin): class SongAdmin(admin.ModelAdmin):
model = Song model = Song
list_display = ('song_title',
list_display = ('song_title', 'song_length', 'lyrics', 'music_video') 'song_length',
'lyrics',
'music_video')
search_fields = ('song_title', 'lyrics') search_fields = ('song_title', 'lyrics')
list_filter = ('song_title',)
list_filter = ('song_title', )
admin.site.register(Artist, ArtistAdmin) admin.site.register(Artist, ArtistAdmin)
......
# Generated by Django 4.1.7 on 2023-02-21 13:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='song',
name='lyrics',
field=models.CharField(max_length=8000),
),
]
...@@ -7,6 +7,9 @@ class Artist(models.Model): ...@@ -7,6 +7,9 @@ class Artist(models.Model):
bio = models.CharField(max_length=700) bio = models.CharField(max_length=700)
monthly_listeners = models.IntegerField() monthly_listeners = models.IntegerField()
def str(self):
return '{} aka {}'.format(self.artist_name, self.birth_name)
class Album(models.Model): class Album(models.Model):
album_name = models.CharField(max_length=100) album_name = models.CharField(max_length=100)
...@@ -16,6 +19,9 @@ class Album(models.Model): ...@@ -16,6 +19,9 @@ class Album(models.Model):
release_date = models.CharField(max_length=10) release_date = models.CharField(max_length=10)
song_count = models.IntegerField() song_count = models.IntegerField()
def str(self):
return '{} aka {}'.format(self.album_name, self.label)
class Song(models.Model): class Song(models.Model):
song_title = models.CharField(max_length=100) song_title = models.CharField(max_length=100)
...@@ -24,3 +30,6 @@ class Song(models.Model): ...@@ -24,3 +30,6 @@ class Song(models.Model):
song_length = models.IntegerField() song_length = models.IntegerField()
music_video = models.BooleanField() music_video = models.BooleanField()
lyrics = models.CharField(max_length=8000) lyrics = models.CharField(max_length=8000)
def str(self):
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