FieldError at/. Cannot resolve keyword 'textField' into field

By : rv_k

I am trying to do a filter method for my django application. I have some fields in db like, userName,designation,employeeID etc . Now i am trying to do a filtering; where there is drop down shows all the fields (name, designation, employeeID etc) and a text area for inputing some text. The filtering should be done based on the drop down choice selection and the data entered in the text area. While doing this i got this error: FieldError at /filter/ Cannot resolve keyword 'textField' into field. Choices are: contactNumber, dateOfJoin, designation, employeeID, id, project, userName I will paste my html and here. Please help me to solve this.

<form action="" method="POST">
Filter By: 
<select name="choices" onsubmit="document.forms[0].submit()" >
    <option value="">Select A Choice</option>
    <option value="Name">Name</option> 
    <option value="Designation" >Designation</option>
    <option value="EmployeeID" >EmployeeID</option>
    <option value="Project" >Project</option>
    <option value="Date Of Join" >Date Of Join</option> 
<input type="text" name="textField">
<input type="submit" value="Go">

{%for data in newData%}
{{ data.userName}}<br>


def filter(request):     
    print val2,val3
    newData = EmployeeDetails.objects.filter(choices=request.POST.get('choices'),textField=request.POST.get('textField'))
    return render_to_response('filter.html',{'newData':newData,'val2':val2,'val3':val3})    


class EmployeeDetails(models.Model):
    userName = models.CharField(max_length=200)
    designation = models.CharField(max_length=200)
    employeeID = models.IntegerField()
    contactNumber = models.CharField(max_length=200)
    project = models.CharField(max_length=200)

I am quite new to Django. Please help me to solve this

By : rv_k


If you don't have one field called "textField" you can't filter your "EmployeeDetails" models. You only can filter the "EmployeeDetails" models with available fields how: "contactNumber, dateOfJoin, designation, employeeID, id, project, userName".


By : Rael Max

If i understand what you are trying to do, you are using filter the wrong way. To filter on a dynamic posted field(val2) with a given query(val3) try.

kwargs = {}
kwargs[val2] = val3

newData = EmployeeDetails.objects.filter(**kwargs)

the option values in you code would need to map the model for this to work.

By : JamesO

This video can help you solving your question :)
By: admin