From cd40fe99ef3def0735a7c572b1d126e9042e0e3f Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Mon, 4 Feb 2013 13:32:21 -0500 Subject: [PATCH] making it faster --- core/models.py | 6 +++--- frontend/views.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/models.py b/core/models.py index 09ade99a..6bb61d38 100755 --- a/core/models.py +++ b/core/models.py @@ -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) diff --git a/frontend/views.py b/frontend/views.py index 67a3e584..b78d2199 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -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)