How to make Django user specific (data) in a to do app?

I am trying to separate tasks between all users that log in, but nothing I've tried has worked. All users are able to see other users' tasks, which isn't what I want. Below is the model and view function that I am using to create a task. Thanks in advance.

class Tasks(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    title = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    complete = models.BooleanField(default=False)
    finish = models.CharField(max_length=50)
    created = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        ordering = ['complete']

Task View

def taskList(request):
    q = request.GET.get('q') if request.GET.get('q') != None else ''
    tasks = Tasks.objects.filter(title__contains=q,user=request.user)
    tasks_count = tasks.count()
    context = {'tasks':tasks, 'tasks_count':tasks_count}

    return render(request, 'base/home.html', context)

Am I missing something in my models?

Back to Top