Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个基于模型的表单,但我想再添加一个字段。该字段不应该在模型上(或者可以,但我不希望它有一个列并保存在数据库中)。
该字段将被传递给视图,并将定义视图将采取的操作(将用于视图上的 if)。
您可以向 ModelForm 添加其他字段:
class FooForm(ModelForm): extra_stuff = forms.CharField() class Meta: model = Foo fields = ['bar', 'biz']