Skip to content

Instantly share code, notes, and snippets.

@greut
Created March 18, 2017 15:46
Show Gist options
  • Save greut/62e7bfb951778316ae303c4b77ba3d8a to your computer and use it in GitHub Desktop.
Save greut/62e7bfb951778316ae303c4b77ba3d8a to your computer and use it in GitHub Desktop.
One view, multiple lists.
from django.views.generic import ListView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Game
class GameListView(LoginRequiredMixin, ListView):
template_name = "games.html"
model = Game
ordering = '-id'
def open_games(self):
qs = self.get_queryset()
return qs.filter(type=Game.GameType.Open)
def running_games(self):
return self.get_queryset().filter(type=Game.GameType.Running)
def done_games(self):
return self.get_queryset().filter(type=Game.GameType.Done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment