Commit 456a10d9 authored by Brian Guadalupe's avatar Brian Guadalupe

Add string representation for the models

parent eacd23d2
from django.db import models from django.db import models
class user_account(models.Model): class UserAccount(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64) first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64) email = models.CharField(max_length=64)
class artist(models.Model): class Artist(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
description = models.TextField() description = models.TextField()
def __str__(self):
return self.name
class album(models.Model): class Album(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
album_name = models.CharField(max_length=64) album_name = models.CharField(max_length=64)
year = models.DecimalField(max_digits=4, decimal_places=0) year = models.DecimalField(max_digits=4, decimal_places=0)
artist = models.ForeignKey(artist) artist = models.ForeignKey(Artist)
def __str__(self):
return self.album_name
class song(models.Model): class Song(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
song_name = models.TextField() song_name = models.TextField()
genre = models.CharField(max_length=128) genre = models.CharField(max_length=128)
song_length = models.PositiveIntegerField(default=0, null=True) song_length = models.PositiveIntegerField(default=0, null=True)
lyrics = models.TextField(null=True) lyrics = models.TextField(null=True)
artist = models.ForeignKey(artist) artist = models.ForeignKey(Artist)
album = models.ForeignKey(album) album = models.ForeignKey(Album)
def __str__(self):
return self.song_name
class music_playlist(models.Model): class MusicPlaylist(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32) playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=False) is_public = models.BooleanField(default=False)
user = models.ForeignKey(user_account) user = models.ForeignKey(UserAccount)
def __str__(self):
return self.playlist_name
class music_entry(models.Model): class MusicEntry(models.Model):
RATING_CHOICES = ( RATING_CHOICES = (
(0,'1'), (0,'1'),
(1,'2'), (1,'2'),
...@@ -48,10 +56,12 @@ class music_entry(models.Model): ...@@ -48,10 +56,12 @@ class music_entry(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
order_in_playlist = models.PositiveSmallIntegerField() order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES) rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
playlist = models.ForeignKey(music_playlist) playlist = models.ForeignKey(MusicPlaylist)
song = models.ForeignKey(song) song = models.ForeignKey(Song)
class tag(models.Model): class Tag(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32) name = models.CharField(max_length=32)
tag = models.ManyToManyField(music_entry) tag = models.ManyToManyField(MusicEntry)
def __str__(self):
return self.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