from django.db import models

class GameQuerySet(models.query.QuerySet):
	"""A lazy database lookup for a set of games"""
	def joinable(self, user=None):
		qs = self.exclude(slots=0)
		if user:
			qs = qs.exclude(player__user=user)
		return qs

	def pending(self, user=None):
		qs = self.filter(slots=0, started__isnull=True)
		if user:
			qs = qs.filter(player__user=user)
		return qs

	def finished(self):
		return self.filter(finished__isnull=False)

@@ -383,71 +383,346 @@
  qs%0A
-%0A%09def finished(self):%0A%09%09return self.filter(finished__isnull=False)
+%09%0A%09def in_progress(self, user=None):%0A%09%09qs = self.filter(started__isnull=False, finished__isnull=True)%0A%09%09if user:%0A%09%09%09qs = qs.filter(player__user=user)%0A%09%09return qs%0A%0A%09def finished(self):%0A%09%09return self.filter(finished__isnull=False)%0A%0A%09def private(self):%0A%09%09return self.filter(private=True)%0A%0A%09def by_teams(self):%0A%09%09return self.filter(teams__gt=0) 
 %0A

add new queries to GameQuerySet