wger-project / wger

Self hosted FLOSS fitness/workout, nutrition and weight tracker
https://wger.de
GNU Affero General Public License v3.0
3.1k stars 578 forks source link

Relation between workout log and session #273

Open rolandgeider opened 8 years ago

rolandgeider commented 8 years ago

Right now the workout logs and the workout session are only linked through the date (for sessions this value is unique and enforced by the DB). This presents in some places a problem, since it's not possible to just follow a foreign key relationship with the ORM like in other places.

To fix this:

remyroo commented 7 years ago

Hi @rolandgeider, I'm part of a small team working on a forked version of Wger as a learning exercise to learn about python, django etc. I have been assigned the task of creating the link between the workout logs and workout sessions and would like to request some clarification.

I apologize in advance if my question seems a little basic, I still have a lot to learn :)

My understanding of database relationships is that you link tables based on the type of queries you'd like to make. If the logs and sessions are already linked by date (and by workout id):

Any help would be much appreciated, thank you! Rehema

rolandgeider commented 7 years ago

Hi @andela-rwachira,

don't worry, first, everybody started one day and second, those questions are not basic :) Also, I'm really happy you chose my project to learn python.

Basically this issue is a "clean up"-issue and would not result in any new user interaction/workflow, at least not in the beginning. Currently, if you have a session and want to find all logs for it, you need so search for all logs that belong to that workout and happened on that day. If it were a foreign key, you could just follow the relation with the ORM, having a cleaner data model design. Basically the difference between this

logs = Log.objects.filter(workout=session.workout, date=session.date)

and this

logs = session.logs.all()

(The same applies to the backward relation, if you have a log and want to get the session)

Also, there are performance improvements if you don't need to perform any searches, indexes on IDs are very fast.

If you have any other questions, feel free to ask!