Version 10 (modified by hartror, 14 years ago) ( diff )

--

Composite Primary Key Design Notes

Collating design considerations, options and decisions here to help get this feature moving.

Design Questions

How do you define multiple primary keys?

The "neatest" solution would be to allow primary_key=True on multiple fields but this may be precluded by other design considerations.

How do you foreign key onto a table with a composite foreign key?

What do you use for .get(pk=foo) with a composite primary key?

The likely solution is to use a tuple or dictionary though there is mention of the comment framework overlapping with this.

Admin urls need a consistent way of mapping a url to an object

Should be able to be handled with some nice url escaping.

Affected Areas

Models

Need a way of defining the primary key.

Generation of the create table SQL.

A solution for foreign keying onto a table with a composite primary key.

Queries

Model.objects.get(pk=foo) needs to be supported.

Forms

Admin

Expect there is a large amount of work in here making sure all the model inspection and form generation works.

Url to object mapping.

Serialization

Code needs to be looked at further but all the foreign keying is likely to need attention.

Relevant Discussions

Note: See TracWiki for help on using the wiki.
Back to Top