We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Filtering my events doesn't work
_Actually I'm not even sure if it's just my local setup that's fucking around or not, but this doesn't seem to work at all.
I can't check with moonshine or prod because everything is down atm, so I'm just making this before I forget._

```
if filters['myevents'] == 'true':
        kwargs['attendance_event__attendees'] = request.user

    events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(
            'attendance_event', 'attendance_event__attendees')
```

in events/views.py _search_indexed

Comparing attendance_event__attendees (Attendee) with request.user (OnlineUser) doesn't make sense. 

It should be attendance_event__attendees__user which from limited testing seems to work. 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/events/views.py`
Content:
```
1 #-*- coding: utf-8 -*-
2 
3 import datetime
4 
5 from django.utils import timezone
6 
7 from django.conf import settings
8 from django.contrib import messages
9 from django.contrib.auth.decorators import login_required, user_passes_test
10 from django.core.urlresolvers import reverse
11 from django.http import HttpResponseRedirect
12 from django.shortcuts import render, get_object_or_404, redirect
13 from django.utils.translation import ugettext as _
14 
15 import watson
16 
17 from apps.events.forms import CaptchaForm
18 from apps.events.models import Event, AttendanceEvent, Attendee
19 from apps.events.pdf_generator import EventPDF
20 
21 
22 def index(request):
23     return render(request, 'events/index.html', {})
24 
25 def details(request, event_id, event_slug):
26     event = get_object_or_404(Event, pk=event_id)
27 
28     is_attendance_event = False
29     user_anonymous = True
30     user_attending = False
31     place_on_wait_list = 0
32     will_be_on_wait_list = False
33     rules = []
34     user_status = False
35 
36     try:
37         attendance_event = AttendanceEvent.objects.get(pk=event_id)
38         is_attendance_event = True
39         form = CaptchaForm(user=request.user)
40 
41         if attendance_event.rule_bundles:
42             for rule_bundle in attendance_event.rule_bundles.all():
43                 rules.append(rule_bundle.get_rule_strings)
44 
45         if request.user.is_authenticated():
46             user_anonymous = False
47             if attendance_event.is_attendee(request.user):
48                 user_attending = True
49 
50             
51             will_be_on_wait_list = attendance_event.will_i_be_on_wait_list
52 
53             user_status = event.is_eligible_for_signup(request.user)
54 
55             # Check if this user is on the waitlist
56             place_on_wait_list = event.what_place_is_user_on_wait_list(request.user)
57 
58     except AttendanceEvent.DoesNotExist:
59         pass
60 
61     if is_attendance_event:
62         context = {
63                 'now': timezone.now(),
64                 'event': event,
65                 'attendance_event': attendance_event,
66                 'user_anonymous': user_anonymous,
67                 'user_attending': user_attending,
68                 'will_be_on_wait_list': will_be_on_wait_list,
69                 'rules': rules,
70                 'user_status': user_status,
71                 'place_on_wait_list': int(place_on_wait_list),
72                 #'position_in_wait_list': position_in_wait_list,
73                 'captcha_form': form,
74         }
75         
76         return render(request, 'events/details.html', context)
77     else:
78         return render(request, 'events/details.html', {'event': event})
79 
80 
81 def get_attendee(attendee_id):
82     return get_object_or_404(Attendee, pk=attendee_id)
83 
84 @login_required
85 def attendEvent(request, event_id):
86     
87     event = get_object_or_404(Event, pk=event_id)
88 
89     if not request.POST:
90         messages.error(request, _(u'Vennligst fyll ut skjemaet.'))
91         return redirect(event)
92 
93     form = CaptchaForm(request.POST, user=request.user)
94 
95     if not form.is_valid():
96         for field,errors in form.errors.items():
97             for error in errors:
98                 messages.error(request, error)
99 
100         return redirect(event)
101 
102     # Check if the user is eligible to attend this event.
103     # If not, an error message will be present in the returned dict
104     attendance_event = event.attendance_event
105 
106     response = event.is_eligible_for_signup(request.user);
107 
108     if response['status']:   
109         Attendee(event=attendance_event, user=request.user).save()
110         messages.success(request, _(u"Du er nå påmeldt på arrangementet!"))
111         return redirect(event)
112     else:
113         messages.error(request, response['message'])
114         return redirect(event)
115 
116 @login_required
117 def unattendEvent(request, event_id):
118 
119     event = get_object_or_404(Event, pk=event_id)
120     attendance_event = event.attendance_event
121 
122     # Check if the deadline for unattending has passed
123     if attendance_event.unattend_deadline < timezone.now():
124         messages.error(request, _(u"Avmeldingsfristen for dette arrangementet har utløpt."))
125         return redirect(event)
126 
127     event.notify_waiting_list(host=request.META['HTTP_HOST'], unattended_user=request.user)
128     Attendee.objects.get(event=attendance_event, user=request.user).delete()
129 
130     messages.success(request, _(u"Du ble meldt av arrangementet."))
131     return redirect(event)
132 
133 def search_events(request):
134     query = request.GET.get('query')
135     filters = {
136         'future' : request.GET.get('future'),
137         'myevents' : request.GET.get('myevents')
138     }
139     events = _search_indexed(request, query, filters)
140 
141     return render(request, 'events/search.html', {'events': events})
142 
143 
144 def _search_indexed(request, query, filters):
145     results = []
146     kwargs = {}
147 
148     if filters['future'] == 'true':
149         kwargs['event_start__gte'] = timezone.now()
150 
151     if filters['myevents'] == 'true':
152         kwargs['attendance_event__attendees'] = request.user
153 
154     events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(
155             'attendance_event', 'attendance_event__attendees')
156 
157     if query:
158         for result in watson.search(query, models=(events,)):
159             results.append(result.object)
160         return results[:10]
161 
162     return events
163 
164 
165 @login_required()
166 @user_passes_test(lambda u: u.groups.filter(name='Komiteer').count() == 1)
167 def generate_pdf(request, event_id):
168 
169     event = get_object_or_404(Event, pk=event_id)
170 
171     groups = request.user.groups.all()
172     if not (groups.filter(name='dotKom').count() == 1 or groups.filter(name='Hovedstyret').count() == 1):
173         if event.event_type == 1 and not groups.filter(name='arrKom').count() == 1:
174             messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))
175             return redirect(event)
176 
177         if event.event_type == 2 and not groups.filter(name='bedKom').count() == 1:
178             messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))
179             return redirect(event)
180 
181         if event.event_type == 3 and not groups.filter(name='fagKom').count() == 1:
182             messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))  
183             return redirect(event)
184 
185     return EventPDF(event).render_pdf()
186
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/events/views.py b/apps/events/views.py
--- a/apps/events/views.py
+++ b/apps/events/views.py
@@ -149,7 +149,7 @@
         kwargs['event_start__gte'] = timezone.now()
 
     if filters['myevents'] == 'true':
-        kwargs['attendance_event__attendees'] = request.user
+        kwargs['attendance_event__attendees__user'] = request.user
 
     events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(
             'attendance_event', 'attendance_event__attendees')

{"golden_diff": "diff --git a/apps/events/views.py b/apps/events/views.py\n--- a/apps/events/views.py\n+++ b/apps/events/views.py\n@@ -149,7 +149,7 @@\n         kwargs['event_start__gte'] = timezone.now()\n \n     if filters['myevents'] == 'true':\n-        kwargs['attendance_event__attendees'] = request.user\n+        kwargs['attendance_event__attendees__user'] = request.user\n \n     events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(\n             'attendance_event', 'attendance_event__attendees')\n", "issue": "Filtering my events doesn't work\n_Actually I'm not even sure if it's just my local setup that's fucking around or not, but this doesn't seem to work at all.\nI can't check with moonshine or prod because everything is down atm, so I'm just making this before I forget._\n\n```\nif filters['myevents'] == 'true':\n        kwargs['attendance_event__attendees'] = request.user\n\n    events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(\n            'attendance_event', 'attendance_event__attendees')\n```\n\nin events/views.py _search_indexed\n\nComparing attendance_event__attendees (Attendee) with request.user (OnlineUser) doesn't make sense. \n\nIt should be attendance_event__attendees__user which from limited testing seems to work. \n\n", "before_files": [{"content": "#-*- coding: utf-8 -*-\n\nimport datetime\n\nfrom django.utils import timezone\n\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required, user_passes_test\nfrom django.core.urlresolvers import reverse\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import render, get_object_or_404, redirect\nfrom django.utils.translation import ugettext as _\n\nimport watson\n\nfrom apps.events.forms import CaptchaForm\nfrom apps.events.models import Event, AttendanceEvent, Attendee\nfrom apps.events.pdf_generator import EventPDF\n\n\ndef index(request):\n    return render(request, 'events/index.html', {})\n\ndef details(request, event_id, event_slug):\n    event = get_object_or_404(Event, pk=event_id)\n\n    is_attendance_event = False\n    user_anonymous = True\n    user_attending = False\n    place_on_wait_list = 0\n    will_be_on_wait_list = False\n    rules = []\n    user_status = False\n\n    try:\n        attendance_event = AttendanceEvent.objects.get(pk=event_id)\n        is_attendance_event = True\n        form = CaptchaForm(user=request.user)\n\n        if attendance_event.rule_bundles:\n            for rule_bundle in attendance_event.rule_bundles.all():\n                rules.append(rule_bundle.get_rule_strings)\n\n        if request.user.is_authenticated():\n            user_anonymous = False\n            if attendance_event.is_attendee(request.user):\n                user_attending = True\n\n            \n            will_be_on_wait_list = attendance_event.will_i_be_on_wait_list\n\n            user_status = event.is_eligible_for_signup(request.user)\n\n            # Check if this user is on the waitlist\n            place_on_wait_list = event.what_place_is_user_on_wait_list(request.user)\n\n    except AttendanceEvent.DoesNotExist:\n        pass\n\n    if is_attendance_event:\n        context = {\n                'now': timezone.now(),\n                'event': event,\n                'attendance_event': attendance_event,\n                'user_anonymous': user_anonymous,\n                'user_attending': user_attending,\n                'will_be_on_wait_list': will_be_on_wait_list,\n                'rules': rules,\n                'user_status': user_status,\n                'place_on_wait_list': int(place_on_wait_list),\n                #'position_in_wait_list': position_in_wait_list,\n                'captcha_form': form,\n        }\n        \n        return render(request, 'events/details.html', context)\n    else:\n        return render(request, 'events/details.html', {'event': event})\n\n\ndef get_attendee(attendee_id):\n    return get_object_or_404(Attendee, pk=attendee_id)\n\n@login_required\ndef attendEvent(request, event_id):\n    \n    event = get_object_or_404(Event, pk=event_id)\n\n    if not request.POST:\n        messages.error(request, _(u'Vennligst fyll ut skjemaet.'))\n        return redirect(event)\n\n    form = CaptchaForm(request.POST, user=request.user)\n\n    if not form.is_valid():\n        for field,errors in form.errors.items():\n            for error in errors:\n                messages.error(request, error)\n\n        return redirect(event)\n\n    # Check if the user is eligible to attend this event.\n    # If not, an error message will be present in the returned dict\n    attendance_event = event.attendance_event\n\n    response = event.is_eligible_for_signup(request.user);\n\n    if response['status']:   \n        Attendee(event=attendance_event, user=request.user).save()\n        messages.success(request, _(u\"Du er n\u00e5 p\u00e5meldt p\u00e5 arrangementet!\"))\n        return redirect(event)\n    else:\n        messages.error(request, response['message'])\n        return redirect(event)\n\n@login_required\ndef unattendEvent(request, event_id):\n\n    event = get_object_or_404(Event, pk=event_id)\n    attendance_event = event.attendance_event\n\n    # Check if the deadline for unattending has passed\n    if attendance_event.unattend_deadline < timezone.now():\n        messages.error(request, _(u\"Avmeldingsfristen for dette arrangementet har utl\u00f8pt.\"))\n        return redirect(event)\n\n    event.notify_waiting_list(host=request.META['HTTP_HOST'], unattended_user=request.user)\n    Attendee.objects.get(event=attendance_event, user=request.user).delete()\n\n    messages.success(request, _(u\"Du ble meldt av arrangementet.\"))\n    return redirect(event)\n\ndef search_events(request):\n    query = request.GET.get('query')\n    filters = {\n        'future' : request.GET.get('future'),\n        'myevents' : request.GET.get('myevents')\n    }\n    events = _search_indexed(request, query, filters)\n\n    return render(request, 'events/search.html', {'events': events})\n\n\ndef _search_indexed(request, query, filters):\n    results = []\n    kwargs = {}\n\n    if filters['future'] == 'true':\n        kwargs['event_start__gte'] = timezone.now()\n\n    if filters['myevents'] == 'true':\n        kwargs['attendance_event__attendees'] = request.user\n\n    events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(\n            'attendance_event', 'attendance_event__attendees')\n\n    if query:\n        for result in watson.search(query, models=(events,)):\n            results.append(result.object)\n        return results[:10]\n\n    return events\n\n\n@login_required()\n@user_passes_test(lambda u: u.groups.filter(name='Komiteer').count() == 1)\ndef generate_pdf(request, event_id):\n\n    event = get_object_or_404(Event, pk=event_id)\n\n    groups = request.user.groups.all()\n    if not (groups.filter(name='dotKom').count() == 1 or groups.filter(name='Hovedstyret').count() == 1):\n        if event.event_type == 1 and not groups.filter(name='arrKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))\n            return redirect(event)\n\n        if event.event_type == 2 and not groups.filter(name='bedKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))\n            return redirect(event)\n\n        if event.event_type == 3 and not groups.filter(name='fagKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))  \n            return redirect(event)\n\n    return EventPDF(event).render_pdf()\n", "path": "apps/events/views.py"}], "after_files": [{"content": "#-*- coding: utf-8 -*-\n\nimport datetime\n\nfrom django.utils import timezone\n\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required, user_passes_test\nfrom django.core.urlresolvers import reverse\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import render, get_object_or_404, redirect\nfrom django.utils.translation import ugettext as _\n\nimport watson\n\nfrom apps.events.forms import CaptchaForm\nfrom apps.events.models import Event, AttendanceEvent, Attendee\nfrom apps.events.pdf_generator import EventPDF\n\n\ndef index(request):\n    return render(request, 'events/index.html', {})\n\ndef details(request, event_id, event_slug):\n    event = get_object_or_404(Event, pk=event_id)\n\n    is_attendance_event = False\n    user_anonymous = True\n    user_attending = False\n    place_on_wait_list = 0\n    will_be_on_wait_list = False\n    rules = []\n    user_status = False\n\n    try:\n        attendance_event = AttendanceEvent.objects.get(pk=event_id)\n        is_attendance_event = True\n        form = CaptchaForm(user=request.user)\n\n        if attendance_event.rule_bundles:\n            for rule_bundle in attendance_event.rule_bundles.all():\n                rules.append(rule_bundle.get_rule_strings)\n\n        if request.user.is_authenticated():\n            user_anonymous = False\n            if attendance_event.is_attendee(request.user):\n                user_attending = True\n\n            \n            will_be_on_wait_list = attendance_event.will_i_be_on_wait_list\n\n            user_status = event.is_eligible_for_signup(request.user)\n\n            # Check if this user is on the waitlist\n            place_on_wait_list = event.what_place_is_user_on_wait_list(request.user)\n\n    except AttendanceEvent.DoesNotExist:\n        pass\n\n    if is_attendance_event:\n        context = {\n                'now': timezone.now(),\n                'event': event,\n                'attendance_event': attendance_event,\n                'user_anonymous': user_anonymous,\n                'user_attending': user_attending,\n                'will_be_on_wait_list': will_be_on_wait_list,\n                'rules': rules,\n                'user_status': user_status,\n                'place_on_wait_list': int(place_on_wait_list),\n                #'position_in_wait_list': position_in_wait_list,\n                'captcha_form': form,\n        }\n        \n        return render(request, 'events/details.html', context)\n    else:\n        return render(request, 'events/details.html', {'event': event})\n\n\ndef get_attendee(attendee_id):\n    return get_object_or_404(Attendee, pk=attendee_id)\n\n@login_required\ndef attendEvent(request, event_id):\n    \n    event = get_object_or_404(Event, pk=event_id)\n\n    if not request.POST:\n        messages.error(request, _(u'Vennligst fyll ut skjemaet.'))\n        return redirect(event)\n\n    form = CaptchaForm(request.POST, user=request.user)\n\n    if not form.is_valid():\n        for field,errors in form.errors.items():\n            for error in errors:\n                messages.error(request, error)\n\n        return redirect(event)\n\n    # Check if the user is eligible to attend this event.\n    # If not, an error message will be present in the returned dict\n    attendance_event = event.attendance_event\n\n    response = event.is_eligible_for_signup(request.user);\n\n    if response['status']:   \n        Attendee(event=attendance_event, user=request.user).save()\n        messages.success(request, _(u\"Du er n\u00e5 p\u00e5meldt p\u00e5 arrangementet!\"))\n        return redirect(event)\n    else:\n        messages.error(request, response['message'])\n        return redirect(event)\n\n@login_required\ndef unattendEvent(request, event_id):\n\n    event = get_object_or_404(Event, pk=event_id)\n    attendance_event = event.attendance_event\n\n    # Check if the deadline for unattending has passed\n    if attendance_event.unattend_deadline < timezone.now():\n        messages.error(request, _(u\"Avmeldingsfristen for dette arrangementet har utl\u00f8pt.\"))\n        return redirect(event)\n\n    event.notify_waiting_list(host=request.META['HTTP_HOST'], unattended_user=request.user)\n    Attendee.objects.get(event=attendance_event, user=request.user).delete()\n\n    messages.success(request, _(u\"Du ble meldt av arrangementet.\"))\n    return redirect(event)\n\ndef search_events(request):\n    query = request.GET.get('query')\n    filters = {\n        'future' : request.GET.get('future'),\n        'myevents' : request.GET.get('myevents')\n    }\n    events = _search_indexed(request, query, filters)\n\n    return render(request, 'events/search.html', {'events': events})\n\n\ndef _search_indexed(request, query, filters):\n    results = []\n    kwargs = {}\n\n    if filters['future'] == 'true':\n        kwargs['event_start__gte'] = timezone.now()\n\n    if filters['myevents'] == 'true':\n        kwargs['attendance_event__attendees__user'] = request.user\n\n    events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(\n            'attendance_event', 'attendance_event__attendees')\n\n    if query:\n        for result in watson.search(query, models=(events,)):\n            results.append(result.object)\n        return results[:10]\n\n    return events\n\n\n@login_required()\n@user_passes_test(lambda u: u.groups.filter(name='Komiteer').count() == 1)\ndef generate_pdf(request, event_id):\n\n    event = get_object_or_404(Event, pk=event_id)\n\n    groups = request.user.groups.all()\n    if not (groups.filter(name='dotKom').count() == 1 or groups.filter(name='Hovedstyret').count() == 1):\n        if event.event_type == 1 and not groups.filter(name='arrKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))\n            return redirect(event)\n\n        if event.event_type == 2 and not groups.filter(name='bedKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))\n            return redirect(event)\n\n        if event.event_type == 3 and not groups.filter(name='fagKom').count() == 1:\n            messages.error(request, _(u'Du har ikke tilgang til listen for dette arrangementet.'))  \n            return redirect(event)\n\n    return EventPDF(event).render_pdf()\n", "path": "apps/events/views.py"}]}