preview site will now show most-wished, not campaigns ending soonest

pull/1/head
Andromeda Yelton 2012-01-15 18:03:54 -05:00
parent aa43bff115
commit d50e9471a4
2 changed files with 19 additions and 10 deletions

View File

@ -474,7 +474,7 @@ class Wishes(models.Model):
created = models.DateTimeField(auto_now_add=True)
source = models.CharField(max_length=15, blank=True)
wishlist = models.ForeignKey('Wishlist')
work = models.ForeignKey('Work')
work = models.ForeignKey('Work', related_name='wishes')
class Meta:
db_table = 'core_wishlist_works'

View File

@ -63,15 +63,24 @@ def home(request):
works=[]
works2=[]
count=ending.count()
while i<12 and count>0:
if i<6:
works.append(ending[j].work)
else:
works2.append(ending[j].work)
i += 1
j += 1
if j == count:
j = 0
# on the preview site there are no active campaigns, so we should show most-wished books instead
is_preview = settings.IS_PREVIEW
if is_preview:
# django related fields and distinct() interact poorly, so we need to do a song and dance to get distinct works
worklist = models.Work.objects.annotate(num_wishes=Count('wishes')).order_by('-num_wishes')
works = worklist[:6]
works2 = worklist[6:12]
else:
while i<12 and count>0:
if i<6:
works.append(ending[j].work)
else:
works2.append(ending[j].work)
i += 1
j += 1
if j == count:
j = 0
events = models.Wishes.objects.order_by('-created')[0:2]
return render(request, 'home.html', {'suppress_search_box': True, 'works': works, 'works2': works2, 'events': events})