Commit 54998bed authored by Daniel W Bond's avatar Daniel W Bond

defined mod querysets

parent 3cc948c1
# core django imports
from django.views.generic import TemplateView, ListView
from django.db.models import Sum
from django.db.models import Count
# third party imports
from braces.views import LoginRequiredMixin, SuperuserRequiredMixin
# imports from your apps
from trades.models import Listing
from core.models import Student
class ModLandingView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
template_name = 'mod.html'
login_url = 'login'
class FlagModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
queryset = Listing.objects.annotate(num_flags=Count('flag')).order_by('-num_flags')[:20]
context_object_name = 'listings'
......@@ -17,8 +20,8 @@ class FlagModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
login_url = 'login'
class ListingNumModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
queryset = Listing.objects.all()[:20]
context_object_name = 'users'
queryset = Student.objects.annotate(num_books=Count('listing')).order_by('-num_books')[:20]
context_object_name = 'students'
template_name = 'listing_num_mod.html'
login_url = 'login'
......@@ -26,5 +29,10 @@ class UserEmailRatioModView(LoginRequiredMixin, SuperuserRequiredMixin, Template
template_name = 'email_ratio_mod.html'
def get_context_data(self, **kwargs):
context = super(UserEmailRatioView, self).get_context_data(**kwargs)
context = super(UserEmailRatioModView, self).get_context_data(**kwargs)
students_by_emails = Student.objects.order_by('-emails_sent')[:20]
students_listings = students_by_emails.annotate(num_books=Count('listing'))
context['email_happy_students'] = students_listings
return context
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment