Nick Heiner
Nick Heiner

Reputation: 122432

Django: Two fields form a key?

I have a model in Django 1.2.4. It has two fields that I would like to act together as a key. Is this possible?

This documentation only talks about a single field being a primary key.

Upvotes: 1

Views: 438

Answers (2)

milkypostman
milkypostman

Reputation: 3043

You may know this already, but one option would be to force the pair is unique and let Django add its own Primary Key. So suppose you want two fields to be a primary key, well, make them unique together and then make each of those fields a db index.

Upvotes: 1

mouad
mouad

Reputation: 70021

Sadly from this link, this ticket is not done yet, you can find more info in the link about how to do it "not directly" .

Upvotes: 0

Related Questions