diff --git a/calendars/views.py b/calendars/views.py index 7517165..77c8d62 100644 --- a/calendars/views.py +++ b/calendars/views.py @@ -76,10 +76,20 @@ class EventUpdateView(LoginRequiredMixin, CoachCheckMixin, UpdateView): template_name = 'calendars/event_form.html' success_url = reverse_lazy('dashboard') + def get_object(self, queryset=None): + # Fetch the event and then check if it's a game or training to return the specific instance + obj = super().get_object(queryset) + if hasattr(obj, 'game'): + return obj.game + if hasattr(obj, 'training'): + return obj.training + return obj + def get_form_class(self): - if hasattr(self.object, 'game'): + # self.object is now the correct child instance because of the overridden get_object + if isinstance(self.object, Game): return GameForm - if hasattr(self.object, 'training'): + if isinstance(self.object, Training): return TrainingForm return EventForm