class Command(models.Model): server = models.ForeignKey(Server) user_login = models.CharFIEld(max_length=100) user_run = models.CharFIEld(max_length=100) host = models.CharFIEld(max_length=100) ip = models.CharFIEld(max_length=100) session = models.CharFIEld(max_length=100) command = models.TextFIEld() ts = models.DateTimeFIEld(auto_Now_add=True) version = models.CharFIEld(max_length=100) type = models.CharFIEld(max_length=100)
我有以下搜索查询
cmds = Command.objects.filter(Q(user_login__contains=form.cleaned_data['loguser']),Q(user_run__contains=form.cleaned_data['runuser']),Q(host__contains=form.cleaned_data['loghost']),Q(command__contains=form.cleaned_data['command']),Q(server__contains=form.cleaned_data['host']),Q(session__contains=form.cleaned_data['session'])) \ .order_by('-ID')[:100]
我需要通过以下字符串搜索server.host
如果我尝试添加以下内容,我会收到一个错误
Q(server__contains=form.cleaned_data['host']),Exception Type: TypeErrorException Value: Related FIEld has invalID lookup: containsException Location: /usr/lib/python2.5/site-packages/django/db/models/fIElds/related.py in get_db_prep_lookup,line 156
form.cleaned_data [‘host’]将包含一个主机名的文本字符串.
解决方法server__searchfIEldname__contains
您没有指定服务器表中的哪个字段应该查找.
总结以上是内存溢出为你收集整理的django foreignkey包含查询全部内容,希望文章能够帮你解决django foreignkey包含查询所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)