django models 关系

1.一对多/多对一

class Entry(models.Model):
    name=models.CharField(max_length=50)
    def __str__(self):
        return self.name

class Blog(models.Model):
    name=models.CharField(max_length=20)
    entry=models.ForeignKey("Entry")     #多对一关键字
    def __str__(self):
        return self.name

  

2.manytomany

3.onetoone

猜你喜欢

转载自www.cnblogs.com/mingxiazhichan/p/9011840.html