mirror of
https://github.com/bspeice/Melodia
synced 2024-12-26 00:28:13 -05:00
Fix the IntegerListField() DB type
This commit is contained in:
parent
4257e33f38
commit
91bc6cf5dd
@ -22,6 +22,9 @@ class IntegerListField(models.TextField):
|
|||||||
#Process a database string
|
#Process a database string
|
||||||
|
|
||||||
#Validation first
|
#Validation first
|
||||||
|
if len(value) <= 0:
|
||||||
|
return []
|
||||||
|
|
||||||
if value[0] != '[' or value[-1] != ']':
|
if value[0] != '[' or value[-1] != ']':
|
||||||
raise ValidationError("Invalid input to parse a list of integers!")
|
raise ValidationError("Invalid input to parse a list of integers!")
|
||||||
|
|
||||||
@ -43,6 +46,6 @@ class IntegerListField(models.TextField):
|
|||||||
|
|
||||||
separator_string = ", "
|
separator_string = ", "
|
||||||
|
|
||||||
list_elements = separator_string.join(value)
|
list_elements = separator_string.join(map(str, value))
|
||||||
|
|
||||||
return "[" + list_elements + "]"
|
return "[" + list_elements + "]"
|
||||||
|
@ -3,3 +3,4 @@ from django.db import models
|
|||||||
# Create your models here.
|
# Create your models here.
|
||||||
from archive import Archive
|
from archive import Archive
|
||||||
from song import Song
|
from song import Song
|
||||||
|
from playlist import Playlist
|
||||||
|
@ -5,7 +5,15 @@ from listfield import IntegerListField
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Playlist model
|
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):
|
class Playlist (models.Model):
|
||||||
@ -91,8 +99,9 @@ class Playlist (models.Model):
|
|||||||
"""Export this internal playlist to a file format."""
|
"""Export this internal playlist to a file format."""
|
||||||
#Default m3u playlist type, support others as I build them.
|
#Default m3u playlist type, support others as I build them.
|
||||||
|
|
||||||
if playlist_type = "pls":
|
if playlist_type == "pls":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#Export m3u, default option
|
#Export m3u, default option
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user