Support unavailable
Please try again later

Composite Key is ready for Django 1.4

by Simone Federici - Michal Petrucha for EuroPython 2012

Currently Django models only support single column primary keys.

Multi-column primary keys support would improve Django integration with legacy databases (whose schema cannot be changed and usualy have multi-column primary keys).

This project allows the usage of django ORM with Multi-Column Primary Key and includes Foreign Key support.

In this talk we will explain the problem, propose a solution and present two projects aiming to solve it.

One of them is a pluggable app which monkey-patches Django’s ORM. Its obvious benefit is you can introduce it in a project without maintaining an unofficial Django fork.

The other one is the long-term solution approved of by the Django core team. It was part of last year’s Google Summer of Code and we will talk about what is ready and what is yet to be done before it is included into mainline Django.

Video

Comments

  1. Gravatar
    I have not watched the video, but I am wondering if there is a solution available as a "monkey patch" pluggable app as described in the abstract to the talk at EuroPython 2012.

    Better yet, is an official solution available in Django itself?

    I would like to use Django with some legacy/warehouse databases, but they ALL use composite keys.

    Thanks for any feedback, suggestions, etc.

    Patrick
  2. Gravatar
    If you can add a column to every table, you can use the fake system using unique together with the keys and id, in the new column.

    but you cannot use the django join table orm system.

    For the official support, you have to help Michal to implement the CFK feature.

    If you need a quick solution as described in the abstract, use my library. It Is not official, is not completed, is not stable, but if you don0t use "django generic features" (not you case) it have to work. If you have problem contact me directly. s.federici@gmail.com

    Here the django ticket:
    https://code.djangoproject.com/ticket/373

    The django wiki page:
    https://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys

    Here my monkeypatch project:
    https://github.com/simone/django-compositekey

    Here Michal django fork.
    https://github.com/koniiiik/django/tree/soc2011/composite-fields
  3. Gravatar
    Yeah, about an official solution... The project is still work in progress. We made some serious advanced during the EuroPython sprints but lately I've had problems catching up with changes upstream related to Py3k compatibility.

New comment

Language
EN
Duration
45 minutes (inc Q&A)

Tagged as

database community django api design architecture sql
Our Sponsors
Spotify
Python Experts
SSL Matrix
Wanna sponsor?