from mutagen.easyid3 import EasyID3

from django.db import models
from django.db.models import IntegerField, CharField, FileField


class Track(models.Model):
    @staticmethod
    def get_track_path(aTrack, filename):
        return 'tracks/%s' % filename

    title = CharField(max_length=255, default='Unnamed', blank=True)
    file = FileField(upload_to=lambda instance, name: instance.get_track_path(instance, name))

    def __unicode__(self):
        return '%s' % (self.title)

@@ -30,16 +30,39 @@
 asyID3%0A%0A
+import uuid%0Aimport os%0A%0A
 from dja
@@ -247,37 +247,415 @@
     
-return 'tracks/%25s' %25 filename
+%22%22%22%0A        Generate a random UUID for a track,%0A        create a two-level directory depth (so that it is indexed by the FS),%0A        use the uuid as the track name%0A        %22%22%22%0A        track_uuid = uuid.uuid4()%0A        lev1 = track_uuid.hex%5B0:8%5D%0A        lev2 = track_uuid.hex%5B8:12%5D%0A        name, extension = os.path.splitext(filename)%0A        return 'tracks/%25s/%25s/%25s%25s' %25 (lev1, lev2, track_uuid, extension)
 %0A%0A  

use uuid for tracks