English 中文(简体)
Django内部人加入遗产表格
原标题:Django inner join on legacy table

我在达詹戈就座,并在遗产数据库上使用这个数据库,我谨作一个非常简单的表格。

Table1:Purchase
PurchaseId(PK)
SupplierId(FK)
Date

Table2:Supplier
SupplierId(PK)
Name

在利用银团之后,它创建了

示范法

class Purchase(models.示范法):
purchaseid = models.AutoField(primary_key=True,db_column=u PurchaseId )
supplierid = models.ForeignKey(Supplier, db_column=u SupplierId )
date = models.DateTimeField(db_column=u Date )

class Supplier(models.示范法):
supplierid = models.AutoField(primary_key=True,db_column=u SupplierId )
name = models.CharField(max_length=45, db_column=u name , blank=True)

根据我所审判的其他职位,我想得出一个简单的共同结果。

观点

def purchaseList(request):
    purchase_list = Purchase.objects.extra(tables=["Supplier"],
                                           where=["Purchase.supplierId = Supplier.supplierid"])
    return render_to_response( purchaseList.html , { purchase_list : purchase_list})

它是正确的办法,也是我如何获得采购。 日期和供应商。 模板中的表格报告的名称? 我曾试图回避回答,但我无法找到答案,我希望这不是一个重复的问题。 很多事事事事事事事事事事事事前会!

最佳回答

你们不需要告诉管理办公室,他们要加入外国钥匙,既不是相应的身份证。 http://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related"rel=“nofollow”https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

问题在于:

purchase_list = Purchase.objects.select_related().all()
问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签