django modelform排除了将数学命名为re的字段

时间:2015-07-02 19:45:25

标签: django modelform

我想从modelform中排除名称中包含某个字符串foo的字段。实施例

class Status(models.Model):
    title = models.CharField(max_length = 400, unique=True)
    title_foo=models.BooleanField()
    ideas = models.ManyToManyField(Idea, through='StatusRelationship')
    ideas_foo=models.BooleanField()
    date_added=models.DateField(default=timezone.now())
    def __str__(self):
        return self.title

我希望排除title_fooideas_foo而不在表单中明确定义exclude=['title_foo','ideas_foo']

1 个答案:

答案 0 :(得分:0)

madzohan的评论解决了我的问题。 exclude=[field.name for field in Status._meta.fields if not 'foo' in field.name]