Hello,
I am trying to order by a column in a joined table. I can obviously sort the list in python, but as I accumulate more data, I will want to filter the results from the database before the result set is returned.
The data model is as follows:
2 core tables: Athletes, Races
1 relationship table: Athlete-Races
A single athlete can sign-up for multiple races.
Multiple athletes can attend the same race.
I am currently trying to display the list of races that an athlete signed up for, or a profile page for that specific athlete.
My server code is (hopefully self-explanatory):
ath_races = app_tables.athlete_races.search( athlete_link=ath_row )
for ar in ath_races:
race_list_result.append({'race_date': ar['race_link']['race_date'], #.strftime('%d-%b-%Y')
'race_name': ar['race_link']['race_name'],
'race_priority': ar['race_prio_link']['priority'],
'race_priority_description': ar['race_prio_link']['priority_description']})
return race_list_result
Is there a way to use the query object to
- only select future races ?
- order the result set in proximity order ?
- change format of date ‘%d-%b-%Y’
I am using a DataGrid on the Athlete Profile page to display the results.
Obviously one solution is to denormalize the race-date value and have it both the Races Table as well as the Athlete-Races relationship table, however, I thought I’d seek a solution that works with a Normalized data model. Any Thoughts ?
From a theoretical perspective, I can see the usefulness of being able to filter query results on a column that accessible via inner join. (In my case, filter the athlete-races table by columns in the race data table … e.g. all races in a location, such a California or Canada, aggregating by date, e.g. athletes racing in September)
I know how to write all the SQL, if there is a “Pass-Through-SQL” mechanism.
Thanks in advance.
Cheers,
Tyler