From d6a2151cdfad28ac6c615f96d16361afdc121e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 5 Aug 2018 00:18:51 +0200 Subject: [PATCH] Rename placeholder for DateTimeRangeField - it is not the most elegant API to work with. --- src/teams/views/tasks.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/teams/views/tasks.py b/src/teams/views/tasks.py index 2d8dac74..aaaed31b 100644 --- a/src/teams/views/tasks.py +++ b/src/teams/views/tasks.py @@ -1,6 +1,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.views.generic import DetailView, CreateView, UpdateView +from django import forms from camps.mixins import CampViewMixin from ..models import Team, TeamTask @@ -22,10 +23,27 @@ class TaskDetailView(CampViewMixin, TeamViewMixin, DetailView): active_menu = 'tasks' +class TaskForm(forms.ModelForm): + class Meta: + model = TeamTask + fields = ['name', 'description', 'when', 'completed'] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.fields['when'].widget.widgets = [ + forms.DateTimeInput( + attrs={"placeholder": "Start"} + ), + forms.DateTimeInput( + attrs={"placeholder": "End"} + ) + ] + + class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView): model = TeamTask template_name = "task_form.html" - fields = ['name', 'description', 'when', 'completed'] + form_class = TaskForm active_menu = 'tasks' def get_team(self): @@ -49,7 +67,7 @@ class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTea class TaskUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, UpdateView): model = TeamTask template_name = "task_form.html" - fields = ['name', 'description', 'when', 'completed'] + form_class = TaskForm active_menu = 'tasks' def get_context_data(self, *args, **kwargs):