Skip to content

Instantly share code, notes, and snippets.

@tbartelmess
Created December 8, 2012 20:49
Show Gist options
  • Save tbartelmess/4241864 to your computer and use it in GitHub Desktop.
Save tbartelmess/4241864 to your computer and use it in GitHub Desktop.
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;
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