Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
DB joining 3 tables in django admin, while searching on the primary table
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aditya Sriram M  
View profile  
 More options May 19 2012, 10:57 am
From: Aditya Sriram M <aditya.cr3...@gmail.com>
Date: Sat, 19 May 2012 07:57:57 -0700 (PDT)
Local: Sat, May 19 2012 10:57 am
Subject: DB joining 3 tables in django admin, while searching on the primary table

Hi,

again, my models are Customer, Users and Devices.

I would like to search by Customer and retrieve all 'select_related' rows
of all the three models.
Eg. like this..

Customer1 User1 Device1
Customer1 User1 Device2
Customer1 User2 Device1
Customer1 User2 Device2
etc etc..

Is this possible in Django? If so how?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Schinckel  
View profile  
 More options May 19 2012, 9:42 pm
From: Matt Schinckel <m...@schinckel.net>
Date: Sat, 19 May 2012 18:42:54 -0700 (PDT)
Local: Sat, May 19 2012 9:42 pm
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table

You may be able to use prefetch_related to do what you want: it will all
depend upon your model structure. select_related is easier, but only
follows an fk in one direction.

Matt.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aditya Sriram M  
View profile  
 More options May 20 2012, 3:42 am
From: Aditya Sriram M <aditya.cr3...@gmail.com>
Date: Sun, 20 May 2012 00:42:17 -0700 (PDT)
Local: Sun, May 20 2012 3:42 am
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table

Ooo.. Nice.

Hmm.. I tried this but it failed? Can you pls correct me?

def queryset(self, request):
        result = super(CustomerAdmin,
self).queryset(request).prefetch_related()
        return result

and my 'display list' for customer admin is..

list_display = ('get_user_name')

where definition of 'get_user_name' is

def get_user_name(self, obj):
        return u'%s %s %s' % (obj.customerid__first_name,
obj.customerid__middle_name, obj.customerid__last_name)
get_user_name.short_description = 'User Name'

where 'first_name', 'middle_name' etc are properties of the 'User' model.

Regards,
Aditya


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aditya Sriram M  
View profile  
 More options May 21 2012, 9:30 am
From: Aditya Sriram M <aditya.cr3...@gmail.com>
Date: Mon, 21 May 2012 06:30:37 -0700 (PDT)
Local: Mon, May 21 2012 9:30 am
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table

Some one there can answer!?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Derek  
View profile  
 More options May 22 2012, 10:10 am
From: Derek <gamesb...@gmail.com>
Date: Tue, 22 May 2012 07:10:56 -0700 (PDT)
Local: Tues, May 22 2012 10:10 am
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table
Please read this:
https://code.djangoproject.com/wiki/UsingTheMailingList#Donts:
before continuing to post these types of messages.

On May 21, 3:30 pm, Aditya Sriram M <aditya.cr3...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
akaariai  
View profile  
 More options May 22 2012, 10:36 am
From: akaariai <akaar...@gmail.com>
Date: Tue, 22 May 2012 07:36:31 -0700 (PDT)
Local: Tues, May 22 2012 10:36 am
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table
On May 22, 5:10 pm, Derek <gamesb...@gmail.com> wrote:

> Please read this:https://code.djangoproject.com/wiki/UsingTheMailingList#Donts:
> before continuing to post these types of messages.

In addition, doing a "django prefetch_related" search on Google might
lead to some clues here...

 - Anssi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bruno desthuilliers  
View profile  
 More options May 23 2012, 5:22 am
From: bruno desthuilliers <bruno.desthuilli...@gmail.com>
Date: Wed, 23 May 2012 02:22:42 -0700 (PDT)
Local: Wed, May 23 2012 5:22 am
Subject: Re: DB joining 3 tables in django admin, while searching on the primary table

On May 20, 9:42 am, Aditya Sriram M <aditya.cr3...@gmail.com> wrote:

> I tried this but it failed? Can you pls correct me?

yes : "it failed" is the worst possible way to describe a problem if
you expect to get some help. If you get an exception and traceback,
please read them carefully, and eventually post them. Else at least
describe the (unexpected) result.

> where definition of 'get_user_name' is

> def get_user_name(self, obj):
>         return u'%s %s %s' % (obj.customerid__first_name,
> obj.customerid__middle_name, obj.customerid__last_name)

What do you expect "obj.customerid__first_name" to eval to exactly ?

> where 'first_name', 'middle_name' etc are properties of the 'User' model.

http://en.wikipedia.org/wiki/Programming_by_permutation ?

I'm sorry to have to say, but it definitly looks like you just don't
have a clue about how Python and Django work. Please take time to
learn at least Python 101, then do Django tutorial. This should answer
your questions and save everyone time on such issues.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »