Ohh this looks little promising.. However,
1. I need a few cols of table1 and few from table 2 to be displayed. How can we achieve that at the .filter() level? and 2. At the view level like using the list_display () for displaying them in the Admin interface On Sunday, 22 April 2012 21:30:41 UTC+5:30, akaariai wrote: > > On Apr 22, 1:31 pm, Aditya Sriram M <aditya.cr3...@gmail.com> wrote: > > File myapp/models.py has this sample code.. > > > > from django.db import models > > > > # model for 'user' table in database oracle_dbuser1:user > > class User(models.Model): > > . . . > > customerid = models.BigIntegerField() > > > > # model for 'customer' table in database oracle_dbuser2:customer > > # Note that there is no Foreign key integrity among these legacy tables. > > class Customer(models.Model): > > . . . > > customerid = models.BigIntegerField() > > > > and the file myapp/admin.py has the following code: > > > > from maasusers.models import User, Customer > > from django.contrib import admin > > > > class UserAdmin(admin.ModelAdmin): > > # A handy constant for the name of the alternate database. > > db_one = 'dbuser1' > > db_two = 'dbuser2' > > > > # display in a list > > list_display = (. . .) # question 1 > > > > def queryset(self, request): > > result = super(UserAdmin, > self).queryset(request).using(self.db_one) # question 2 > > return result > > > > # Register the Poll class > > admin.site.register(User, UserAdmin) > > admin.site.register(Customer, UserAdmin) > > > > Question 1: Refer above: I want to display columns of both the tables. > How > > can I achieve this? Eg.Select usr.col1, usr.col2, cust.col1, cust.col10 > > from user usr, customer cust where usr.col2 = cust.col3; > > > > Question 2: How to write a corresponding queryset() function using the > using > > function? > > There is no way to do a join between models if there is no relation > between them. I see two ways forward: modify one of the models to have > a foreign key - even if there is no foreign key in the DB, you can > have one in the models - or do the join in Python (fetch all > customers, then fetch users by > User.objects.filter(customerid__in=[obj.customerid for obj in > customers]). Finally join users to its customer). > > - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/1qtlv3JUuRMJ. 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.