默认值关联
class Org(models.Model):
"""
组织架构
"""
name = models.CharField("组织机构名称", max_length=100, default='')
pid = models.ForeignKey('self', verbose_name="上级", on_delete=models.CASCADE, related_name='parent_org',
blank=None, null=True, default=None)
pids = ArrayField(models.CharField(max_length=32), default=None, null=True)
oid = models.CharField("旧ID", max_length=100, null=True, blank=True, default='')
class Meta:
db_table = 'edu_org'
verbose_name = verbose_name_plural = '组织架构表'
修改关联到其他字段
class Org(models.Model):
"""
组织架构
"""
name = models.CharField("组织机构名称", max_length=100, default='')
pid = models.ForeignKey(on_delete=models.CASCADE, to_field='oid',
related_name='org_code', db_column='prarent_id',
to='self')
pids = ArrayField(models.CharField(max_length=32), default=None, null=True)
oid = models.CharField("旧ID", max_length=100, null=True, blank=True, default='')
class Meta:
db_table = 'edu_org'
verbose_name = verbose_name_plural = '组织架构表'
标签:name,models,max,默认,Django,default,外键,CharField,True
From: https://www.cnblogs.com/guanchaoguo/p/17849243.html