related = cache.get(cache_key)
if related is None:
related = Book.tagged.related_to(book,
- Book.objects.exclude(common_slug=book.common_slug),
- ignore_by_tag=book.book_tag())[:limit-random]
+ Book.objects.exclude(common_slug=book.common_slug)
+ ).exclude(tag_relations__tag=book.book_tag())[:limit-random]
cache.set(cache_key, related, 1800)
if random:
random_books = Book.objects.exclude(
if random == 1:
count = random_books.count()
if count:
- related.append(random_books[randint(0, count - 1)])
+ random_related = [random_books[randint(0, count - 1)]]
else:
- related += list(random_books.order_by('?')[:random])
+ random_related = list(random_books.order_by('?')[:random])
+ else:
+ random_related = []
return {
'books': related,
+ 'random_related': random_related,
}
@register.simple_tag
def source_name(url):
+ url = url.lstrip()
netloc = urlparse(url).netloc
+ if not netloc:
+ netloc = urlparse('http://' + url).netloc
+ if not netloc:
+ return ''
source, created = Source.objects.get_or_create(netloc=netloc)
return source.name or netloc