django - how to use contains or startwith in join query -


i want use contains in join query gives error.

following models.py:

 class profile(models.model):      name = models.charfield(max_length=50, primary_key=true)      assign = models.charfield(max_length=50)      doj = models.datefield()      dob = models.datefield()       class meta:         db_table = u'profile'       def __str__(self):          return  '%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)       def __unicode__(self):          return  u'%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)       enter code here  class working(models.model):    w_name =models.foreignkey(profile, db_column='w_name')    monday =  models.integerfield(null=true, db_column='monday', blank=true)    tuesday =  models.integerfield(null=true, db_column='tuesday', blank=true)    wednesday =  models.integerfield(null=true, db_column='wednesday', blank=true)     class meta:         db_table = u'working'     def __str__(self):          return  '%s %s %s %s' % ( self.w_name,self.monday,self.tuesday,self.wednesday)     def __unicode__(self):          return  u'%s %s %s %s' % ( self.w_name,self.monday,self.tuesday,self.wednesday) 

i want use this:

m = working.objects.filter(w_name__name__contains='sushanth')  or   m = working.objects.filter(w_name__name__startswith='sushanth') 

the error keep getting:

     file "<console>", line 1, in <module>   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/manager.py", line 141, in filter     return self.get_query_set().filter(*args, **kwargs)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/query.py", line 556, in filter     return self._filter_or_exclude(false, *args, **kwargs)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/query.py", line 574, in _filter_or_exclude     clone.query.add_q(q(*args, **kwargs))   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/sql/query.py", line 1152, in add_q     can_reuse=used_aliases)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/sql/query.py", line 1092, in add_filter     connector)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/sql/where.py", line 67, in add     value = obj.prepare(lookup_type, value)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/sql/where.py", line 316, in prepare     return self.field.get_prep_lookup(lookup_type, value)   file "/usr/local/lib/python2.6/dist-packages/django-1.2.4-py2.6.egg/django/db/models/fields/related.py", line 139, in get_prep_lookup     raise typeerror("related field has invalid lookup: %s" % lookup_type) typeerror: related field has invalid lookup: startswith 

any suggestions??

is there reason why name field primary key?

if there isn't suggest recreating tables name field not primary key. might throwing filter logic out.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -