Hello,

I want to filter data in the database to retrieve only those tasks with 
status='In progress'. I have used the filter queryset, but am getting an 
error. Please help.

*Here is my view (Filter tasks by their status):*

def tasks_in_progress(request):
    tasks = Task.objects.filter(Status='In progress')
    context = {'tasks': tasks}
    #return render(request,"todoapp/show_task.html",{'tasks':tasks})
    return render(request,"todoapp/tasks_in_progress.html", context)



*The model.py*

class Task(models.Model):
    #Task_Title = models.ForeignKey(ToDoList, on_delete=models.CASCADE)
    Task_Title = models.CharField(max_length=500)
    Task_Description = models.CharField(max_length=500)
    Priority = models.ForeignKey(Task_Priority, on_delete=models.CASCADE)
    Date_Created = models.DateTimeField(auto_now_add=True)
    Completion_Date = models.DateTimeField()
    Assigned_To = models.ForeignKey(User, blank=True, null=True, 
on_delete=models.SET_NULL)
    Status = models.ForeignKey(Task_Status, on_delete=models.CASCADE)

    def __str__(self):
        return self.Task_Description

*The error am getting is:*

ValueError at /todoapp/tasks_in_progress

Field 'id' expected a number but got 'In progress'.

Request Method: GET
Request URL: http://127.0.0.1:8000/todoapp/tasks_in_progress
Django Version: 3.0.2
Exception Type: ValueError
Exception Value: 

Field 'id' expected a number but got 'In progress'.

Exception Location: C:\Users\Chuck 
Madamombe\Desktop\djangoPROJECTS\lib\site-packages\django\db\models\fields\__init__.py
 
in get_prep_value, line 1772
Python Executable: C:\Users\Chuck 
Madamombe\Desktop\djangoPROJECTS\Scripts\python.exe
Python Version: 3.7.1
Python Path: 

['C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS',
 'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS\\Scripts\\python37.zip',
 'C:\\Users\\Chuck '
 'Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
 'C:\\Users\\Chuck '
 'Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
 'C:\\Users\\Chuck Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32',
 'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS',
 'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS\\lib\\site-packages',
 'C:\\Users\\Chuck '
 
'Madamombe\\Desktop\\djangoPROJECTS\\lib\\site-packages\\setuptools-39.1.0-py3.7.egg']

Server time: Sun, 9 Feb 2020 10:22:05 +0200


But if I just retrieve all the records in the database, without filtering, 
its working without an error



*My View to retrieve all the records in the database, without filtering.*

def show_task(request):
    tasks = Task.objects.all()
    context = {'tasks': tasks}
    #return render(request,"todoapp/show_task.html",{'tasks':tasks})
    return render(request,"todoapp/show_task.html", context)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a13041e8-1c37-4722-bf64-4faa75dd56ff%40googlegroups.com.

Reply via email to