# 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)
if self.has_media("txt"):
formats.append(u'<a href="%s">TXT</a>' % 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'<a href="%s">%s</a>' % m.type, m.file.url)
-
+
formats = [mark_safe(format) for format in formats]
setattr(self, key, unicode(render_to_string('catalogue/book_short.html',