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.
当一个字段在模型中被标记为“editable=False”时,它不会出现在生成的表单上。字段如何初始化并保存到数据库中?
由你,在 python 代码中。例如,如果您的对象有一个不可编辑的user字段:
user
form = MyForm(request.POST) if form.is_valid(): myobj = form.save(commit=False) myobj.user = request.user myobj.save()