X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dd48571cf22a0c124b382a1c26f25204aefd05f3..2ec21919225b7132331a5367d026d1e1738a5b89:/apps/catalogue/models.py diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index f811461be..fa6c13225 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) @@ -208,7 +212,7 @@ class Book(models.Model): epub_file = models.FileField(_('EPUB file'), upload_to=book_upload_path('epub'), blank=True) txt_file = models.FileField(_('TXT file'), upload_to=book_upload_path('txt'), blank=True) # other files - medias = models.ManyToManyField(BookMedia) + medias = models.ManyToManyField(BookMedia, blank=True) parent = models.ForeignKey('self', blank=True, null=True, related_name='children') objects = models.Manager()