from django.db import models
from datetime import timedelta

# Create your models here.



class Cd(models.Model):
    id = models.BigIntegerField(primary_key=True)
    artist = models.CharField(max_length=200, blank=True, null=True)
    title = models.CharField(max_length=200, blank=True, null=True)
    year = models.SmallIntegerField(blank=True, null=True)
    genre = models.CharField(max_length=50, blank=True, null=True)
    company = models.CharField(max_length=100, blank=True, null=True)
    cpa = models.CharField(max_length=100, blank=True, null=True)
    arrivaldate = models.DateField(blank=True, null=True)
    copies = models.SmallIntegerField(blank=True, null=True)
    compilation = models.SmallIntegerField(blank=True, null=True)
    demo = models.SmallIntegerField(blank=True, null=True)
    local = models.SmallIntegerField(blank=True, null=True)
    female = models.SmallIntegerField(blank=True, null=True)
    createwho = models.BigIntegerField(blank=True, null=True)
    createwhen = models.BigIntegerField(blank=True, null=True)
    modifywho = models.BigIntegerField(blank=True, null=True)
    modifywhen = models.BigIntegerField(blank=True, null=True)
    comment = models.TextField(blank=True, null=True)
    status = models.SmallIntegerField(blank=True, null=True)
    format = models.SmallIntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'cd'

    def __unicode__(self):
        return self.artist + " - " + self.title


class Cdcomment(models.Model):
    cdid = models.BigIntegerField()
    cdtrackid = models.BigIntegerField()
    comment = models.TextField(blank=True, null=True)
    createwho = models.BigIntegerField()
    createwhen = models.BigIntegerField()
    modifywho = models.BigIntegerField()
    modifywhen = models.BigIntegerField()

    class Meta:
        managed = False
        db_table = 'cdcomment'


class Cdtrack(models.Model):
    trackid = models.BigIntegerField(primary_key=True)
    album = models.ForeignKey(Cd, db_column='cdid', related_name="tracks")
    tracknum = models.BigIntegerField()
    tracktitle = models.CharField(max_length=200, blank=True, null=True)
    trackartist = models.CharField(max_length=200, blank=True, null=True)
    tracklength = models.BigIntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'cdtrack'

class Show(models.Model):
    show = models.CharField(max_length=200)
    defaultHost = models.CharField(max_length=200, blank=True)
    startTime = models.TimeField();
    endTime = models.TimeField();

class Playlist(models.Model):
    show = models.CharField(max_length=200)
    host = models.CharField(max_length=200)
    date = models.DateField()
    notes = models.TextField(blank=True, null=True)
    complete = models.BooleanField(default=False)

class PlaylistEntry(models.Model):
    playlist = models.ForeignKey(Playlist)
    # text entry
    artist = models.CharField(max_length=200, blank=False, null=False)
    album = models.CharField(max_length=200, blank=False, null=False)
    title = models.CharField(max_length=200, blank=False, null=False)
    duration = models.DurationField(blank=True, null=True, default=timedelta());

    #quotas
    local = models.BooleanField()
    australian = models.BooleanField()
    female = models.BooleanField()
    newRelease = models.BooleanField()
    
    #found in catalogue
    catalogueEntry = models.ForeignKey(Cdtrack, null=True)

@@ -2829,16 +2829,94 @@
 False)%0A%0A
+    def __unicode__(self):%0A        return self.show + ' - ' + str(self.date)%0A%0A
 class Pl
@@ -3530,20 +3530,130 @@
 Cdtrack, null=True)%0A
+%0A    def __unicode__(self):%0A        return '(' + self.playlist.show + ') ' + self.artist + %22 - %22 + self.title%0A

Add __unicode__methods to Playlist and PlaylistEntry models.