I inherited a Django application that serves high school sports information. I recently received a request to modify a certain set of data so information is displayed only from the current season, which I accomplished this way:
teams = Team.objects.filter(season__school_year__in=school_year_filter_list)
(school_year_filter_list
contains [1,3]
)
This query causes an error in pgpool (a Postgres database pooling/replication utility) so I cannot use it. As a side note, the query works properly in the Python shell, and when I bypass pgpool and use Postgres directly. However, our network architecture dictates the use of pgpool, so I am trying to find an alternate way to retrieve the same data.
Can you help me determine another way to get all Teams with a Season in the current SchoolYear?
The (simplified) models look like this:
class Team(models.Model):
season = models.ForeignKey(Season)
class Season(models.Model):
school_year = models.ForeignKey(SchoolYear, blank=True, null=True)
class SchoolYear(models.Model):
school_year = models.CharField(max_length=150)
The '_schoolyear' table looks like:
id | school_year
----+-------------
1 | 2010-2011
2 | 2009-2010
3 | 2011-2012
In the end, I modified another model to make this work. Rather than parsing years to get active seasons, I added an "active" flag to the SchoolYear model and modified my query to check for that flag:
def queryset(self, request):
qs = super(PlayerYearAdmin, self).queryset(request)
return qs.filter(team__season__school_year__active=True)