Views can have an indirect relation to a team.
This commit is contained in:
parent
02977acd5e
commit
d08c299e8d
|
@ -37,7 +37,11 @@ class EnsureTeamMemberResponsibleMixin(SingleObjectMixin):
|
|||
|
||||
|
||||
class TeamViewMixin:
|
||||
|
||||
def get_team(self):
|
||||
return self.get_object().team
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['team'] = self.get_object().team
|
||||
context['team'] = self.get_team()
|
||||
return context
|
||||
|
|
|
@ -25,6 +25,12 @@ class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTea
|
|||
template_name = "task_form.html"
|
||||
fields = ['name', 'description']
|
||||
|
||||
def get_team(self):
|
||||
return Team.objects.get(
|
||||
camp__slug=self.kwargs['camp_slug'],
|
||||
slug=self.kwargs['team_slug']
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
task = form.save(commit=False)
|
||||
task.team = self.team
|
||||
|
|
Loading…
Reference in a new issue