I am trying to create materialized view in postgresql using django by following this blog post.
my models are:
class Occasion(models.Model):
name = models.CharField(max_length=100)
class ItemType(models.Model):
name = models.CharField(max_length=100)
class Dress(models.Model):
name = models.CharField(max_length=100)
item_type = models.ForeignKey(ItemType)
occasions = models.ManyToManyField(Occasion)
# ... more fields
Now, I create a model corresponding to the materialized view (purpose of creating this view is to minimize join queries):
class DressMaterializedView(models.Model):
name = models.CharField(max_length=100)
item_type_name = models.CharField(max_length=100) # note this
occasion_names = models.ArrayField( # and this
models.CharField(max_length=100) # and compare it with Dress model above
)
class Meta:
managed = False
db_table = "dresses_dressmv"
Now, What SQL query (ie. CREATE MATERIALIZED VIEW dresses_dressmv ...) do I write to create the materialized view I intend to.
Thanks in advance.