I have been learning django from few days. I have couple of models , and these perfectly show up on the admin site , once i register the models in 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 . 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. 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).
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.
"""