Autonaming medias.
authorLukasz Anwajler <lukasz@anwajler.com>
Mon, 22 Nov 2010 20:44:39 +0000 (14:44 -0600)
committerLukasz Anwajler <lukasz@anwajler.com>
Mon, 22 Nov 2010 20:44:39 +0000 (14:44 -0600)
apps/catalogue/migrations/0005_many2many_files_for_books.py
apps/catalogue/models.py

index 664045b..44411f0 100644 (file)
@@ -32,7 +32,7 @@ class Migration(SchemaMigration):
         db.create_table('catalogue_bookmedia', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
             ('type', self.gf('django.db.models.fields.CharField')(max_length='100')),
         db.create_table('catalogue_bookmedia', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
             ('type', self.gf('django.db.models.fields.CharField')(max_length='100')),
-            ('name', self.gf('django.db.models.fields.CharField')(max_length='100')),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length='100', blank=True)),
             ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100, blank=True)),
             ('uploaded_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
         ))
             ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100, blank=True)),
             ('uploaded_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
         ))
index 98e37c1..fa6c132 100644 (file)
@@ -173,13 +173,17 @@ def book_upload_path(ext=None):
         # how to put related book's slug here?
         if not ext:
             ext = media.type
         # how to put related book's slug here?
         if not ext:
             ext = media.type
-        return 'lektura/%s.%s' % (slugify(media.name), ext)
+        if not media.name:
+            name = slugify(filename.split(".")[0])
+        else:
+            name = slugify(media.name)
+        return 'lektura/%s.%s' % (name, ext)
     return get_dynamic_path
 
 
 class BookMedia(models.Model):
     type        = models.CharField(_('type'), choices=MEDIA_FORMATS, max_length="100")
     return get_dynamic_path
 
 
 class BookMedia(models.Model):
     type        = models.CharField(_('type'), choices=MEDIA_FORMATS, max_length="100")
-    name        = models.CharField(_('name'), max_length="100")
+    name        = models.CharField(_('name'), max_length="100", blank=True)
     file        = models.FileField(_('file'), upload_to=book_upload_path(), blank=True)    
     uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
 
     file        = models.FileField(_('file'), upload_to=book_upload_path(), blank=True)    
     uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)