Created
December 8, 2012 20:49
-
-
Save tbartelmess/4241864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN; | |
CREATE TABLE "cars_car" ( | |
"id" integer NOT NULL PRIMARY KEY, | |
"model" varchar(200) NOT NULL, | |
"color" varchar(200) NOT NULL | |
) | |
; | |
CREATE TABLE "cars_person_cars" ( | |
"id" integer NOT NULL PRIMARY KEY, | |
"person_id" integer NOT NULL, | |
"car_id" integer NOT NULL REFERENCES "cars_car" ("id"), | |
UNIQUE ("person_id", "car_id") | |
) | |
; | |
CREATE TABLE "cars_person" ( | |
"id" integer NOT NULL PRIMARY KEY, | |
"firstname" varchar(200) NOT NULL, | |
"lastname" varchar(200) NOT NULL | |
) | |
; | |
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from modelmixins import ModelMixin | |
class Car(models.Model): | |
model = models.CharField(max_length=200) | |
color = models.CharField(max_length=200) | |
class CarOwner(ModelMixin): | |
cars = models.ManyToManyField(Car) | |
class Person(models.Model, CarOwner): | |
firstname = models.CharField(max_length=200) | |
lastname = models.CharField(max_length=200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment