[英]when i use this filter for the host field it throws an error "Related Field got invalid lookup: icontains"
当我使用host__icontains时,如何使用过滤器方法过滤搜索栏中的主机或用户,它会引发错误,所以我该如何解决这个问题
def home(request): q = request.GET.get('q') if request.GET.get('q') != None else '' rooms = Room.objects.filter( Q(topic__name__icontains = q) | Q(name__icontains= q)| Q(discription__icontains =q)| Q(host__icontains =q)) topics = Topic.objects.all() context = {'rooms':rooms, 'topics':topics} return render(request,'home.html',context) #modules class Room(models.Model): host = models.ForeignKey(User, on_delete=models.SET_NULL, null= True) topic = models.ForeignKey(Topic, on_delete= models.SET_NULL, null= True) name = models.CharField(max_length=200) discription = models.TextField(null=True, blank=True) class Message(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) room = models.ForeignKey(Room, on_delete=models.CASCADE) body = models.TextField() updated = models.DateTimeField(auto_now= True) created = models.DateTimeField(auto_now_add= True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.