so I am trying to make a recurring task based on frequency defined in in the table.
here is the model:
class Task(models.Model):
task_id = models.AutoField(primary_key=True)
task_name = models.CharField(max_length=100)
frequency = models.IntegerField()
frequency_units = models.CharField(max_length=10, choices=UNIT, default=1)
next_due = models.DateTimeField(default=timezone.now)
warning = models.IntegerField()
warning_units = models.CharField(max_length=10, choices=UNIT, default=1)
lab = models.ForeignKey(Lab, on_delete=models.PROTECT)
where frequency units are choices like Daily, Weekly and so on and frequency a delta from that i.e. 2 Daily would be every second day the task is due.
The Views are as below if it matters:
class tasks(ListView):
template_name = "tasks.html"
model = Task
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['task'] = Task.objects.all()
return context
class task_create(CreateView):
template_name = "create.html"
model = Task
form_class = addTaskForm
success_url = reverse_lazy("tasks")
def form_valid(self, form):
form.save()
messages.success(self.request, "New task setup.")
return super(task_create, self).form_valid(form)
class task_edit(UpdateView):
model = Task
template_name = "edit.html"
form_class = addTaskForm
success_url = reverse_lazy("tasks")
def form_valid(self, form):
form.save()
messages.success(self.request, "Update uploaded successfully.")
return super(task_edit, self).form_valid(form)
def get_object(self):
pk = Task.objects.get(task_id=self.kwargs.get("task_id"))
return Task.objects.get(task_id=pk)
Is there a way in Django where I can update the next_due column to the tune of the respective frequency after the task has been marked as complete while still keeping record of the date it was marked as complete.