我想从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_foo
和ideas_foo
而不在表单中明确定义exclude=['title_foo','ideas_foo']
答案 0 :(得分:0)
madzohan的评论解决了我的问题。 exclude=[field.name for field in Status._meta.fields if not 'foo' in field.name]