Reputation: 393
I have a table my django model is pointing to, db side i set a series of triggers to route information in child tables (by table inheritance) for a rotation system. Querying the parent table i can still have my full set of information even if dislocated in many tables,but to improve my performance i want to search only in parent table, corresponding with a query where i specify "ONLY" to make db not search in child tables. Is there a way to do it with django models?
Upvotes: 0
Views: 89
Reputation: 1559
You can create a view in postgres:
CREATE OR REPLACE VIEW my_view AS
SELECT * FROM ONLY MY_TABLE;
Create a model in django pointing to that view:
class MyModel(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
class Meta:
managed = False
db_table = 'my_view'
Then query that model. Or you can use directly .raw()
Upvotes: 1