【发布时间】:2026-01-19 10:55:02
【问题描述】:
在下面的类中,'dep' 是一个与 Employee 模型关联的外键字段。
Views.py
class Sample(ListAPIView)
queryset=Employee.Objects.all()
serializer_class = EmployeeSerializer
filter_backends = [SearchFilter]
search_fields = ['dep']
模型.py
class Employee(models.Model):
FirstName=models.CharField(max_length=30)
LastName = models.CharField(max_length=30)
Salary = models.FloatField()
Email = models.CharField(max_length=35)
Dep =models.Foreignkey(Department)
但是当我将 dep has a filter 传递给 endpt 时,它会抛出 Related Field got invalid lookup: icontains 错误。
【问题讨论】:
标签: python python-3.x django django-models django-rest-framework