Is there any support for inheritance of tables?

2 views
Skip to first unread message

jocknerd

unread,
Jul 22, 2005, 10:36:12 PM7/22/05
to django-d...@googlegroups.com
I'm working on a project with a postgresql table called game. It has
basic information about a game. Then I have another table called
playoff_game which inherits the game table and adds a few extra fields.
This is done easily in postgresql. For example:

CREATE TABLE game (
game_id SERIAL PRIMARY KEY,
scheduled_date DATE,
game_date DATE,
season_id INTEGER REFERENCES season_lookup (id),
team1_id INTEGER REFERENCES school_lookup (id),
team1_score INTEGER,
team2_id INTEGER REFERENCES school_lookup (id),
team2_score INTEGER,
attendance INTEGER,
location TEXT NOT NULL DEFAULT '',
team1_forfeit BOOLEAN DEFAULT 'N',
team2_forfeit BOOLEAN DEFAULT 'N',
district_game BOOLEAN DEFAULT 'Y',
notes TEXT
);

CREATE TABLE playoff_game (
playoff_type_id INTEGER REFERENCES playoff_type_lookup (id),
region_id INTEGER REFERENCES region_lookup (id),
classification_id INTEGER REFERENCES classification_lookup (id)
) INHERITS (game)

How would I implement this in django using models?

Robin Munn

unread,
Jul 22, 2005, 11:31:23 PM7/22/05
to django-d...@googlegroups.com
On 7/22/05, jocknerd <jeff...@gmail.com> wrote:
>
> I'm working on a project with a postgresql table called game. It has
> basic information about a game. Then I have another table called
> playoff_game which inherits the game table and adds a few extra fields.
> This is done easily in postgresql. For example:
>
> How would I implement this in django using models?

I think you want a OneToOneField, see
http://www.djangoproject.com/documentation/db_api/#one-to-one-relations
.

BTW, is there a django-users list yet to handle these kinds of questions?

--
Robin Munn
Robin...@gmail.com
GPG key 0xD6497014

Jacob Kaplan-Moss

unread,
Jul 22, 2005, 11:39:54 PM7/22/05
to django-d...@googlegroups.com
On Jul 22, 2005, at 10:31 PM, Robin Munn wrote:
> BTW, is there a django-users list yet to handle these kinds of
> questions?

Yes there is; it's called -- wait for it -- django-users!

http://googlegroups.com/group/django-users

Jacob
Reply all
Reply to author
Forward
0 new messages