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?