Question:
Solved: TaskList View in Django

Creating a TaskList view in Django involves defining a view that retrieves and displays a list of tasks from the database. Here is the code to make a TaskList View in Django:


class TaskList(LoginRequiredMixin, ListView):

    model = Task

    context_object_name = 'tasks'


    def get_queryset(self):

        return super().get_queryset().filter(user=self.request.user)


    def get_context_data(self, **kwargs):

        context = super().get_context_data(**kwargs)

        context['count'] = self.object_list.filter(complete=False).count()

        return context


You might also want to filter on complete=False in get_queryset.

Note: Since> PEP-3135 [pep], you don't need to call super(…) with parameters if the first parameter is the class in which you define the method, and the second is the first parameter (usually self) of the function.


Suggested blogs:

>How to Create_function deprecated in PHP?

>How to delete duplicate names from Array in Typescript?

>How to do PHP Decryption from Node.js Encryption

>How to do PHP Decryption from Node.js Encryption?

>How to do PHP gd Installation on Ubuntu?

>How to do Web Scraping with Python?



Ritu Singh

Ritu Singh

Submit
0 Answers