X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/84aecebd96f2bc8a27396ecf10c409a8b91e1bcc..58a39e2d8614b5ec1d8ffc6ae5268fa94f555736:/apps/catalogue/models.py?ds=sidebyside
diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py
index 98e37c1af..5b33dcc1a 100644
--- a/apps/catalogue/models.py
+++ b/apps/catalogue/models.py
@@ -173,13 +173,17 @@ def book_upload_path(ext=None):
# 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")
- 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)
@@ -351,9 +355,9 @@ class Book(models.Model):
if self.has_media("txt"):
formats.append(u'TXT' % self.get_media('txt').url)
# other files
- for m in self.media.order_by('type'):
+ for m in self.medias.order_by('type'):
formats.append(u'%s' % m.type, m.file.url)
-
+
formats = [mark_safe(format) for format in formats]
setattr(self, key, unicode(render_to_string('catalogue/book_short.html',