I have a simple todolist app where each task has a Booleanfield called is_deleted. in my list template, I only want to show the tasks with is_deleted=False .
I know I can use Task.objects.all().filter(is_deleted=False) in my view; but I want to do it with managers in my template. here is my manager:
class TaskManager(models.Manager):
def available(self):
return self.filter(is_deleted=False)
.
.
objects = TaskManager()
here is my view:
class TaskList(ListView):
model = models.Task
context_object_name="tasks"
template_name = "home/list.html"
paginate_by=5
and here is the the condition in my template:
{% if tasks.available%} ...