Commit 328336ec authored by Ron Rodillas's avatar Ron Rodillas

fixed an issue with the model filters and added string functions to the models

parent 37eaf101
...@@ -14,14 +14,14 @@ class AlbumAdmin(admin.ModelAdmin): ...@@ -14,14 +14,14 @@ class AlbumAdmin(admin.ModelAdmin):
list_display = ("album_name", "description", "release_date", "label", "song_count") list_display = ("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", "song_length", "lyrics", "music_video") list_display = ("song_title", "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)
admin.site.register(Album, AlbumAdmin) admin.site.register(Album, AlbumAdmin)
......
# Generated by Django 4.1.7 on 2023-02-21 11:10
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=100)),
('description', models.TextField()),
('release_date', models.DateField()),
('label', models.CharField(max_length=100)),
('song_count', models.IntegerField()),
],
),
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=100)),
('birth_name', models.CharField(max_length=100)),
('bio', models.CharField(max_length=700)),
('monthly_listeners', models.IntegerField()),
],
),
migrations.CreateModel(
name='Song',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('song_title', models.CharField(max_length=100)),
('song_length', models.IntegerField()),
('music_video', models.BooleanField(default=False)),
('lyrics', models.TextField()),
('album', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='about.album')),
('artist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='about.artist')),
],
),
migrations.AddField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='about.artist'),
),
]
...@@ -7,6 +7,8 @@ class Artist(models.Model): ...@@ -7,6 +7,8 @@ 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 '{}'.format(self.artist_name)
class Album(models.Model): class Album(models.Model):
album_name = models.CharField(max_length=100) album_name = models.CharField(max_length=100)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE) artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
...@@ -15,6 +17,9 @@ class Album(models.Model): ...@@ -15,6 +17,9 @@ class Album(models.Model):
label = models.CharField(max_length=100) label = models.CharField(max_length=100)
song_count = models.IntegerField() song_count = models.IntegerField()
def __str__(self):
return '{}'.format(self.album_name)
class Song(models.Model): class Song(models.Model):
song_title = models.CharField(max_length=100) song_title = models.CharField(max_length=100)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE) artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
...@@ -22,4 +27,7 @@ class Song(models.Model): ...@@ -22,4 +27,7 @@ class Song(models.Model):
song_length = models.IntegerField() song_length = models.IntegerField()
music_video = models.BooleanField(default=False) music_video = models.BooleanField(default=False)
lyrics = models.TextField() lyrics = models.TextField()
def __str__(self):
return '{}'.format(self.song_title)
\ No newline at end of file
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