-
字段类型
from django.db import models # Create your models here. # 自定义模型必须继承Model class User(models.Model): # 字段名:不能是python的关键字;不能使用连续的下划线; #db_column:数据库表中的字段名称 uid = models.AutoField(primary_key=True) # CharField类型必须指明长度max_length username = models.CharField(max_length=30,unique=True) password = models.CharField(max_length=128) regtime = models.DateTimeField(auto_now_add=True) class Meta: # 元数据,模型本身的信息 #默认表名:应用名_模型名 db_table = 'user' # 表名 ordering = ['username'] # 排序
class User(models.Model): uid = models.AutoField(primary_key=True) username = models.CharField(max_length=30,null=False) password = models.CharField(max_length=128,null=False) regtime = models.DateTimeField(auto_now=True) sex = models.IntegerField() def __str__(self): return self.username+":"+ str(self.uid) class Meta: db_table = 'user' class Detail(models.Model): did = models.AutoField(primary_key=True) phone = models.CharField(max_length=30) uid = models.IntegerField() class Meta: db_table = 'detail'
Django—模型—字段类型
猜你喜欢
转载自blog.csdn.net/piduocheng0577/article/details/105001772
今日推荐
周排行