Django数据库之多对多的创建

from django.db import models


# Create your models here.
class userType(models.Model):
    name=models.CharField(max_length=32)
    def __str__(self):
        return self.name#可以返回名字了
class userInfo(models.Model):
    nid=models.AutoField(primary_key=True)
    name=models.CharField(max_length=32)
    email=models.EmailField()
    text=models.TextField()
    image=models.ImageField()
    user_type=models.ForeignKey(userType,null=True,blank=True)
class B2G(models.Model):#多对多数据结构模式创建
    boy=models.ForeignKey("Boy")
    girl=models.ForeignKey("Girl")
class Boy(models.Model):
    name=models.CharField(max_length=32)
class Girl(models.Model):
    name=models.CharField(max_length=32)
   # f=models.ManyToManyField(Boy)

你可能感兴趣的:(Python自动化开发)