Opened 12 years ago

Closed 11 years ago

#20314 closed New feature (wontfix)

provide a management command to database views to cover inheritance

Reported by: chris@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

if you use inheritance like this:

class Foo(models.Model):
  a = models.CharField(max_length=10)

class Bar(Foo):
  b = models.CharField(max_length=10)

That will lead to two tables being created:

create table myapp_foo(id int, a varchar(10));
create table myapp_bar(foo_id, b varchar(10));

That's great. But when I need to run queries directly against the database, I have to write all the joins myself. Since I'm (extraordinarily) lazy, I would love to see a new management command that creates a view like this:

create view bar_view as -- i hate that name, but it's good for an example
select *                -- if I did this for real, I would enumerate the columns
from myapp_foo
join myapp_bar on myapp_foo.id = myapp_bar.foo_id

for this trivial example, the typing isn't that much. But when you get deep inheritance hierachies, the typing becomes a pain (especially since the name of the "id" key keeps changing at each level).

Change History (1)

comment:1 by Russell Keith-Magee, 11 years ago

Resolution: wontfix
Status: newclosed

I can see what you're asking for here, and I can see the value, but Django doesn't currently have *any* support for views, so this seems a little premature.

In the meantime, you don't have to create the joins -- Django's ORM will create the joins for you.

Note: See TracTickets for help on using tickets.
Back to Top