Here are my models:
class Activity(models.Model):
title = models.CharField(blank=False, max_length=100)
description = models.TextField(blank=False)
class UserActivityWork(models.Model):
activity = models.ForeignKey(Activity)
user = models.ForeignKey(User)
hours_worked = models.FloatField()
comment = models.TextField()
Example data would be, an Activity of "climbing Mt Everest" and each user would be able to input how long it took them and a comment.
Here's my question: How can I display a list of all the Activities, and if the user has entered data for that Activity, display the pertinent details next to the Activity?
So far, I have considered:
- creating a dictionary of UserActivityWork with a key of the Activity id and a value of the user's UserActivityWork. This would be fine with me, but I have no idea of how to do this in django's templating system (ie, how do you say: {{ user_work[activity.id] }})
- creating an object that would hold both the Activity and UserActivityWork. I haven't done this one, because I am hoping that django has a better way to do this.
Any insight would be greatly appreciated!