[英]database view on django admin site
I have been learning django from few days. 我从几天开始学习django。 I have couple of models , and these perfectly show up on the admin site , once i register the models in admin.py.
我有几个模型,一旦我在admin.py中注册了模型,这些模型就会完美地显示在管理站点上。 But i want to create
database view
(not the view
which django refers) , i have created the model for the view, with managed = False
on models.py . 但是我想创建
database view
(而不是django引用的view
),我已经创建了该视图的模型,在models.py上使用managed = False
。 this database view is a join of two tables. 该数据库视图是两个表的联接。 and when i start my server, i get error some saying that my database view is not a table , which is correct.
当我启动服务器时,出现错误,提示我的数据库视图不是table,这是正确的。 But I am missing some thing here that i unable to solve this.
但是我在这里缺少一些我无法解决的问题。 what might be that i am missing.
我可能想念的是什么。 or is my whole idea of database view itself wrong , if so how do i do this - is it allays , that i have to run sql( of course using django db api).
还是我对数据库视图本身的整个想法是错误的,如果是这样,我该怎么做-可以吗,我必须运行sql(当然要使用django db api)。
Heres my code. 这是我的代码。
class product(models.Model):
users = models.ForeignKey(User)
product = models.CharField(max_length=20)
def __unicode__(self):
return self.product
class product_models(models.Model):
product = models.ForeignKey('product')
model_name = models.CharField(max_length=50)
model_price = models.IntegerField(max_length=4)
model_desc = models.TextField(blank=True)
commision = models.IntegerField(max_length=3)
def __unicode__(self):
return self.model_name
class my summary_view(model.Model):
# this is my database view
product = models.ForeignKey('product')
model_name = models.ForeignKey('product_models')
class meta :
managed = False
"""
I am assuming this is what above code does, I may be wrong also here in creating
database view in the above table .
Create View `summary_view` as
Select
p.product, m.model_name
From
products p , product_model m.
"""
Your view is called summary_view, but django would by default look for appname_summary_view, either: 您的视图称为summary_view,但是django默认情况下将查找appname_summary_view,或者:
Add 加
class meta:
db_table = 'summary_view'
managed = False
Or update your view 或更新您的视图
create view 'appname_summary_view'...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.