X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5eaa85a6a703ca0d05063850211eddc414a912b4..9e556c1938577b991edfcb0a0248fcca92d67f3e:/apps/catalogue/models.py
diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py
index ab480d7fc..b78b5939b 100644
--- a/apps/catalogue/models.py
+++ b/apps/catalogue/models.py
@@ -156,7 +156,7 @@ class Tag(TagBase):
# TODO: why is this hard-coded ?
-def book_upload_path(ext=None):
+def book_upload_path(ext=None, maxlen=100):
def get_dynamic_path(media, filename, ext=ext):
# how to put related book's slug here?
if not ext:
@@ -165,17 +165,25 @@ def book_upload_path(ext=None):
name = slughifi(filename.split(".")[0])
else:
name = slughifi(media.name)
- return 'lektura/%s.%s' % (name, ext)
+ return 'lektura/%s.%s' % (name[:(maxlen-len('lektura/.%s' % ext))], 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", blank=True)
- file = models.FileField(_('file'), upload_to=book_upload_path(), blank=True)
+ name = models.CharField(_('name'), max_length="100")
+ file = models.FileField(_('file'), upload_to=book_upload_path())
uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
extra_info = JSONField(_('extra information'), default='{}')
+ def book_count(self):
+ return self.book_set.count()
+ book_count.short_description = _('book count')
+
+ def books(self):
+ return mark_safe('
'.join("%s" % (reverse('admin:catalogue_book_change', args=[b.id]), b.title) for b in self.book_set.all()))
+ books.short_description = _('books')
+
def __unicode__(self):
return "%s (%s)" % (self.name, self.file.name.split("/")[-1])