making it faster

pull/1/head
Andromeda Yelton 2013-02-04 13:32:21 -05:00
parent 1afdd5e21f
commit cd40fe99ef
2 changed files with 11 additions and 5 deletions

View File

@ -206,7 +206,7 @@ class Campaign(models.Model):
target = models.DecimalField(max_digits=14, decimal_places=2, null=True, blank=False)
license = models.CharField(max_length=255, choices = LICENSE_CHOICES, default='CC BY-NC-ND')
left = models.DecimalField(max_digits=14, decimal_places=2, null=True, blank=False)
deadline = models.DateTimeField()
deadline = models.DateTimeField(db_index=True)
activated = models.DateTimeField(null=True)
paypal_receiver = models.CharField(max_length=100, blank=True)
amazon_receiver = models.CharField(max_length=100, blank=True)
@ -565,7 +565,7 @@ class Work(models.Model):
title = models.CharField(max_length=1000)
language = models.CharField(max_length=2, default="en", null=False)
openlibrary_lookup = models.DateTimeField(null=True)
num_wishes = models.IntegerField(default=0)
num_wishes = models.IntegerField(default=0, db_index=True)
description = models.TextField(default='', null=True)
class Meta:
@ -924,7 +924,7 @@ class Ebook(models.Model):
provider = models.CharField(max_length=255)
# use 'PD-US', 'CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA', 'CC0'
rights = models.CharField(max_length=255, null=True, choices = RIGHTS_CHOICES)
rights = models.CharField(max_length=255, null=True, choices = RIGHTS_CHOICES, db_index=True)
edition = models.ForeignKey('Edition', related_name='ebooks')
user = models.ForeignKey(User, null=True)

View File

@ -528,9 +528,15 @@ class UngluedListView(FilterableListView):
return models.Work.objects.filter(campaigns__status="SUCCESSFUL").distinct().order_by('-campaigns__deadline')
elif (facet == 'cc' or facet == 'creativecommons'):
# assumes all ebooks have a PD or CC license. compare rights_badge property
return models.Work.objects.filter(editions__ebooks__isnull=False).exclude(editions__ebooks__rights__in=['PD-US', 'CC0', '']).distinct().order_by('-num_wishes')
return models.Work.objects.filter(
editions__ebooks__isnull=False,
editions__ebooks__rights__in=['CC BY', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC', 'CC BY-ND', 'CC BY-SA']
).distinct().order_by('-num_wishes')
elif (facet == 'pd' or facet == 'publicdomain'):
return models.Work.objects.filter(editions__ebooks__isnull=False).filter(editions__ebooks__rights__in=['PD-US', 'CC0', '']).distinct().order_by('-num_wishes')
return models.Work.objects.filter(
editions__ebooks__isnull=False,
editions__ebooks__rights__in=['PD-US', 'CC0', '']
).distinct().order_by('-num_wishes')
def get_context_data(self, **kwargs):
context = super(UngluedListView, self).get_context_data(**kwargs)