2009-04-21 15 views
9

शामिल मैं निम्नलिखित मॉडलDjango foreignkey क्वेरी

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:  TypeError 
Exception Value:  

Related Field has invalid lookup: contains 

Exception Location:  /usr/lib/python2.5/site-packages/django/db/models/fields/related.py in get_db_prep_lookup, line 156 

form.cleaned_data ['host'] में होस्टनाम के लिए एक टेक्स्ट स्ट्रिंग होगी।

उत्तर

16
server__searchfieldname__contains 

आपने यह निर्दिष्ट नहीं किया है कि सर्वर तालिका में कौन सा फ़ील्ड दिखना चाहिए।

+0

अरे क्या आप इसके लिए कुछ दस्तावेज लिंक प्रदान कर सकते हैं? –

संबंधित मुद्दे