I'm having trouble figuring out how to filter a queryset appropriately for the following scenario.
I have an event with many participants. Both models are imported from a foreign data source, so I want to keep a permanent copy of their data:
class Event(models.Model):
address = etc...
class Participant(models.Model):
event = models.ForeignKey('Event')
user_profile = models.ForeignKey('people.UserProfile', blank=True, null=True)
name = etc...
When the foreign data source receives a new event, it sends me a copy, which I fill into these models. The import script uses the Participant's name field to try and find them in its existing list of people, and if so, it establishes the foreign key.
I have the currently logged in UserProfile on hand, and Event.objects.all. I want to filter the Events by the currently logged in user. What should the arguments to .filter() be to achieve this?
Event.filter(participants__user_profile=UserProfile.objects.get(user=get_current_user()))...