parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
ancestor = models.ManyToManyField('self', blank=True, editable=False, related_name='descendant', symmetrical=False)
+ cached_author = models.CharField(blank=True, max_length=240, db_index=True)
+ has_audience = models.BooleanField(default=False)
+
objects = models.Manager()
tagged = managers.ModelTaggedItemManager(Tag)
tags = managers.TagDescriptor(Tag)
return split_tags(self.tags.exclude(category__in=('set', 'theme')))
def author_unicode(self):
- return self.tag_unicode('author')
+ return self.cached_author
def translator(self):
translators = self.extra_info.get('translators')
others = ''
return ', '.join(u'\xa0'.join(reversed(translator.split(', ', 1))) for translator in translators) + others
+ def cover_source(self):
+ return self.extra_info.get('cover_source', self.parent.cover_source() if self.parent else '')
+
def save(self, force_insert=False, force_update=False, **kwargs):
from sortify import sortify
author = u''
self.sort_key_author = author
+ self.cached_author = self.tag_unicode('author')
+ self.has_audience = 'audience' in self.extra_info
+
ret = super(Book, self).save(force_insert, force_update, **kwargs)
return ret
else:
return None
+ def fragment_data(self):
+ fragment = self.choose_fragment()
+ if fragment:
+ return {'title': fragment.book.pretty_title(), 'html': fragment.get_short_text()}
+ else:
+ return None
+
def update_popularity(self):
count = self.tags.filter(category='set').values('user').order_by('user').distinct().count()
try: