django的模型挺好的,不用自己写SQL。外键,多对多,一对多,多对一。
# app_1/models.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from app_2.models import App2Model1, App2Model2
class App1Model1(models.Model):
field_1 = models.IntegerField()
field_2 = models.IntegerField()
field_3 = models.IntegerField()
field_4 = models.ForeignKey(App2Model1)
field_5 = models.ForeignKey(App2Model2)
field_6 = models.ForeignKey("App1Model2", on_delete=models.CASCADE)
class App1Model2(models.Model):
field_1 = models.CharField(max_length=500)
field_2 = models.CharField(max_length=1)
field_3 = models.ForeignKey(App2Model1)
field_4 = models.CharField(max_length=500)
参考:
Django Project