Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3799298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:42:38+00:00 2026-05-19T13:42:38+00:00

How to write joins in django,i have gone through below django documentation ,but joins

  • 0

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

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

and models/many_to_many/

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'

     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 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…………………….?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:42:39+00:00Added an answer on May 19, 2026 at 1:42 pm

    Please format your question so that the code is readable (the {} icon) otherwise it is very hard to read.

    working.objects.filter(name= will fail because your working model doesn’t have a name field.

    From the docs you linked to:

    Django offers a powerful and intuitive
    way to “follow” relationships in
    lookups, taking care of the SQL JOINs
    for you automatically, behind the
    scenes. To span a relationship, just
    use the field name of related fields
    across models, separated by double
    underscores
    , until you get to the
    field you want.

    That translates to:

    m = working.objects.filter(w_name__name='sushanth').select_related()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
Hi I am trying to write a tagging system for Django, but today I
I have a large, messy report to write that joins across 5 tables. There
I need to write a select query that joins the tables based on a
I feel like I am writing something that should already exist. Does Django have
I am new to django (and have no experience in SQL), so maybe there
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
I have a model that I would like to contain a subjects name and
I'm trying to add a field to a Django model that will represent a
Write a class ListNode which has the following properties: int value; ListNode *next; Provide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.