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’)
- Django: Firefox doesn't use the loaded CSS
- How can I create session- or cookie-based user identity in Django?
- If else statement to check for date entered
- How to access extended profile in django (1.9.4)
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'
- How to pass variable from view page to base template
- Django – Permission Error when opening pipe to write
- Replacement for filterby in vuejs 2
Source:stackexchange.com