python学习笔记-django(3)--orm创建表关系

from django.db import models

# Create your models here.
#用户表
class User(models.Model):
    username = models.CharField(max_length=32,verbose_name='用户名')
    password = models.CharField(max_length=32,verbose_name='密码')
    #choices参数,针对一些可以列举完全可能性的片段
    gender_choices = ((1,'男'),(2,'女'),(3,'保密'))
    gender = models.IntegerField(choices=gender_choices)
    email = models.EmailField(null=True)

#英雄表
class Hero(models.Model):
    hero_name = models.CharField(max_length=32)
    hero_background_information = models.TextField()
    #英雄和阵营表是1对多关系,外键放在多的一方
    camp = models.ForeignKey(to='Camp')


#英雄台词
class hero_dialogu(models.Model):
    #英雄台词
    hero_dialogues = models.CharField(max_length=255)
    #英雄和英雄台词表1对多关系,外键放在多的一方
    hero = models.ForeignKey(to='Hero')


#阵营表-背景介绍
class Camp(models.Model):
        camp_choices = ((1,'艾欧尼亚'),(2,'洛克萨斯'),(3,'均衡教派'))
        camp = models.IntegerField(choices=camp_choices)
        camp_background_information = models.TextField(null=True)


#推荐装备表
class RecommendEquipment(models.Model):
    equipment = models.CharField(max_length=32)
    equipment_information = models.TextField(null=True)
    #英雄和推荐装备,本来应该放在查询频率较高的英雄一方
    #这里练习放在装备表中
    hero = models.ManyToManyField(to='Hero')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值