django 中各个models之前可以有继承关系、这种继承关系又可以分成三种情况:
1、简单继承
2、抽象继承
3、代理
一、简单继承:
model定义
from django.db import models # Create your models here. class Person(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name class Student(Person):
sid = models.IntegerField() def __str__(self):
return self.sid
对应SQL
BEGIN;
--
-- Create model Person
--
CREATE TABLE "polls_person" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(100) NOT NULL
);
--
-- Create model Student
--
CREATE TABLE "polls_student" (
"person_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "polls_person" ("id"),
"sid" integer NOT NULL
); COMMIT;
play with api
----