HI,

How to write joins in django,i have gone through below django documentation 
,but joins are not working for my model

http://www.djangoproject.com/documentation/models/many_to_many/

http://docs.djangoproject.com/en/1.2/topics/db/queries/#lookups-that-span-relationships

and some blogs

My Model :


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'

    class __str__(self):
         return  '%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)

  class __unicode__(self):
         return  u'%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)


Class working(models.model)
  w_name =models.ForeignKey(Profile, db_column='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'

  lass __str__(self):
         return  '%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)

  class __unicode__(self):
         return  u'%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)


I am trying to do join between two tables profile and workingday

     like m=working.objects.filter(name='sushanth').select_related()


if i run above query i'll get 
  
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 129, 
in filter
    return self.get_query_set().filter(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 498, 
in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 516, 
in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1675, in add_q
    can_reuse=used_aliases)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1569, in add_filter
    negate=negate, process_extras=process_extras)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1737, in setup_joins
    "Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'name' into field. Choices are:  monday,  
tuesday, wednesday,  w_name


I need to query where i can join working and profile.

support 

 select working.*,profile.assign,profile.doj from working join profile where 
name=w_name ;

I know django won't support joins,inner join  is also okay for me.

Can any one help on this.........................?






  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to