[Fixed]-Django 1.7 / 1.8 Cannot resolve keyword

1👍

It should be

Deptcontacts.objects.filter(dept__dept_name__contains='Pub')
👤Othman

0👍

Never mind. I see where I was making my boo boo.

I have

class Department(models.Model):
    dept_name = models.TextField(max_length=200)

class Deptcontacts(models.Model):
    dept = models.ForeignKey(Department)
    contact_name = models.TextField(max_length=200)
    contact_phone = models.TextField(max_length=200)

And this
Deptcontacts.objects.filter(department__dept_name__contains=’Pub’)

Should be
Deptcontacts.objects.filter(dept__dept_name__contains=’Pub’)

👤JotDot

0👍

You are getting this error because there is no field department in your model Department.

To use .filter(**kwargs) on a queryset, kwargs should be model fields.

You need to do something like:

Deptcontacts.objects.filter(dept__dept_name='PublicWorks') # use model field 'dept' 

Deptcontacts.objects.filter(dept__dept_name__contains='Pub') # use model field 'dept' 

Leave a comment