macaron
macaron copied to clipboard
SQLite view support
Sometimes, it is very convenient to use a view instead of a table.
Let us imagine a page with a side block showing the 10 last twits. In your template you need the author's id and name. It is very easy to prepare it in a view, and shurely faster to read it than invoquing twit.author.name.
Is it possible to think a "read_only" class for working with views ?
I follow my idea with an example.
-- create Article
CREATE TABLE article (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"title" TEXT,
"pub_date" TEXT,
"author" TEXT,
"content" TEXT,
"creation_date" TIMESTAMP,
"keywords" TEXT DEFAULT ('NULL')
-- create Available
CREATE VIEW "available" AS SELECT * FROM article
WHERE pub_date IS NOT NULL
AND pub_date < date('now')
and in macaron models
class Article(macaron.Model):
title = macaron.CharField(max_length=64)
author = macaron.CharField(max_length=64)
content = macaron.CharField()
pub_date = macaron.DateField(null=True)
creation_date = macaron.TimestampAtCreate()
keywords = macaron.CharField(null=True)
class Available(macaron.View, Article):
"""" read only view"""
id = macaron.ViewField(Article.pk)
title = macaron.ViewField(Article.title)
author = macaron.ViewField(Article.author)
content = macaron.ViewField(Article.content)
pub_date = macaron.ViewField(Article.pub_date)
creation_date = macaron.ViewField(Article.creation_date)
keywords = macaron.ViewField(Article.keywords)
Just a suggestion...
Hi, Your suggestion seems nice. And, in case of such as fetching author.name, the strategy may contribute its performance. I prepare the next release of Macaon, after that, I'll make a study on the suggestion.
Hi, It could be a parent class of the Field class, kind of read-only field.