# create task based on Frequency defined

**URL:** <https://forum.djangoproject.com/t/create-task-based-on-frequency-defined/34074>\
**Category:** Using Django\
**Created:** [August 22, 2024, 2:49am UTC](https://forum.djangoproject.com/t/create-task-based-on-frequency-defined/34074 "2024-08-22T02:49:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nephrithos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/nephrithos/32/23384_2.png) [@Nephrithos](https://forum.djangoproject.com/u/Nephrithos)\
**Post date:** [August 22, 2024, 2:49am UTC](https://forum.djangoproject.com/t/create-task-based-on-frequency-defined/34074/1 "2024-08-22T02:49:43Z")

</div>

so I am trying to make a recurring task based on frequency defined in in the table.

here is the model:

```auto
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:

```auto
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.
