Gre*_*reg 4 python database django models
我正在创建自己的Group模型; 我不是指内置Group模型.我希望每个hroup都是另一个组(它的父组)的成员,但是有一个"top"组没有父组.
管理界面不允许我在不输入父级的情况下创建组.我收到了错误personnel_group.parent_id may not be NULL.我的Group模型看起来像这样:
class Group(models.Model):
name = models.CharField(max_length=50)
parent = models.ForeignKey('self', blank=True, null=True)
order = models.IntegerField()
icon = models.ImageField(upload_to='groups', blank=True, null=True)
description = models.TextField(blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点?
谢谢.
我在添加blank=True, null=True到parent字段定义之前创建了数据库.syncdb无法处理这种类型的更改,因此Django没有接受我的更改.
我删除了我的数据库,让syncdb创建另一个,它工作正常.
| 归档时间: |
|
| 查看次数: |
3463 次 |
| 最近记录: |