我想限制在Django forms.ModelForm
我可以限制更新中显示哪些字段并创建表单,但不能解决如何为表单的列表视图执行此操作。
我的模型看起来像这样:
class Teacher(models.Model):
name = models.CharField(max_length=255)
email = models.CharField(max_length=30)
slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
我的观看代码如下所示:
class TeacherListView(GroupRequiredMixin, ListView):
model = Teacher
group_required = [u"school_admin"]
login_url = "/login/"
我的表单代码如下:
class TeacherForm(forms.ModelForm):
class Meta:
model = Teacher
fields = ['name', 'email' ]
我试图隐藏列表视图中的slug字段。
答案 0 :(得分:0)
你可以试试这个
class TeacherForm(forms.ModelForm):
class Meta:
model = Teacher
exclude = ['slug']