文件myapp/models.py
有这个示例代码..
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()
该文件myapp/admin.py
具有以下代码:
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)
问题1:参考上面:我想显示两个表的列。我怎样才能做到这一点?例如。Select usr.col1, usr.col2, cust.col1, cust.col10 from user usr, customer cust where usr.col2 = cust.col3;
问题2:如何queryset()
使用函数编写对应的using
函数?