gazeta_link = models.CharField(blank=True, max_length=240)
wiki_link = models.CharField(blank=True, max_length=240)
+ created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+ changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
+
categories_rev = {
'autor': 'author',
'epoka': 'epoch',
def get_dynamic_path(media, filename, ext=ext):
# how to put related book's slug here?
if not ext:
- ext = media.type
+ if media.type == 'daisy':
+ ext = 'daisy.zip'
+ else:
+ ext = media.type
if not media.name:
name = slughifi(filename.split(".")[0])
else:
name = slughifi(media.name)
- return 'lektura/%s.%s' % (name[:(maxlen-len('lektura/.%s' % ext))], ext)
+ return 'lektura/%s.%s' % (name[:maxlen-len('lektura/.%s' % ext)-4], 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('<br/>'.join("<a href='%s'>%s</a>" % (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])
title = models.CharField(_('title'), max_length=120)
slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
description = models.TextField(_('description'), blank=True)
- created_at = models.DateTimeField(_('creation date'), auto_now_add=True)
+ created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+ changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
_short_html = models.TextField(_('short HTML'), editable=False)
parent_number = models.IntegerField(_('parent number'), default=0)
extra_info = JSONField(_('extra information'))
tag.save()
book_tags.append(tag)
- book.tags = book_tags + book_shelves
+ book.tags = set(book_tags + book_shelves)
book_tag = book.book_tag()