I understand Django doesn't support database views
(http://en.wikipedia.org/wiki/View_%28database%29) right out of the
box, but I was wondering if there's a reasonably easy way to implement
(or at least emulate) them. Here's an illustration of a possible API
(compatible to the magic-removal DB API):
from django.db.models import *
# Regular (physical) tables
class Poll(Model):
question = CharField(maxlength=200)
pub_date = DateTimeField('date published')
class Choice(Model):
poll = ForeignKey(Poll)
choice = CharField(maxlength=200)
votes = IntegerField()
# Virtual (logical) table
from django.db.views import View
class PollChoice(View):
Fields = {
Poll : ['question', 'pub_date'],
Choice : ['choice', 'votes']
}
class Admin:
list_display = ['question','choice']
# Then,
PollChoice.objects.filter(pub_date__lte=datetime.datetime.now(),
votes__gt=10)
# translates to
# SELECT Poll.question, Choice.choice
# FROM Poll, Choice
# WHERE Choice.poll_id=Poll.id AND Poll.pub_date<=NOW() AND
Choice.votes>10
Has anyone though of/implemented anything close to this ?
George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---