diff --git a/archiver/listfield.py b/archiver/listfield.py index d1d5c38..204c633 100644 --- a/archiver/listfield.py +++ b/archiver/listfield.py @@ -22,6 +22,9 @@ class IntegerListField(models.TextField): #Process a database string #Validation first + if len(value) <= 0: + return [] + if value[0] != '[' or value[-1] != ']': raise ValidationError("Invalid input to parse a list of integers!") @@ -43,6 +46,6 @@ class IntegerListField(models.TextField): separator_string = ", " - list_elements = separator_string.join(value) + list_elements = separator_string.join(map(str, value)) return "[" + list_elements + "]" diff --git a/archiver/models.py b/archiver/models.py index da5acfc..e277f24 100644 --- a/archiver/models.py +++ b/archiver/models.py @@ -3,3 +3,4 @@ from django.db import models # Create your models here. from archive import Archive from song import Song +from playlist import Playlist diff --git a/archiver/playlist.py b/archiver/playlist.py index 0003d77..c4d7c6d 100644 --- a/archiver/playlist.py +++ b/archiver/playlist.py @@ -5,7 +5,15 @@ from listfield import IntegerListField """ Playlist model -Each playlist is a high-level ordering of songs. That's really it... +Each playlist is a high-level ordering of songs. There really isn't much to a playlist - just its name, and the songs inside it. +However, we need to have a way to guarantee song order, in addition to re-ordering. A ManyToMany field can't do this. +As such, a custom IntegerListField is implemented - it takes a python list of ints, converts it to a text field in the DB, +and then back to a python list. This way, we can guarantee order, and have a song appear multiple times. +The IntegerListField itself uses the ID of each song as the int in a list. For example, a list of: + [1, 3, 5, 17] + +Means that the playlist is made up of four songs. The order of the playlist is the song with index 1, 3, 5, and 17. +Additionally, the ManyToMany field is included to make sure we don't use the global Songs manager - it just seems hackish. """ class Playlist (models.Model): @@ -91,8 +99,9 @@ class Playlist (models.Model): """Export this internal playlist to a file format.""" #Default m3u playlist type, support others as I build them. - if playlist_type = "pls": + if playlist_type == "pls": pass else: #Export m3u, default option + pass