我正在使用来自django-extra-views
的CreateWithInlinesView
。在这种情况下,如何检索当前用户?在
我现在有这样的东西
class PublisherCreateView(CreateWithInlinesView):
model = Publisher
inlines = [BookInline,]
def form_valid(self, form, inlines):
form.instance.created_by = self.request.user
return super(PublisherCreateView, self).form_valid(form, inlines)
这仍然返回(1048, "Column 'created_by_id' cannot be null")
的错误。在
编辑:把我的编辑变成一个答案
这是因为
CreateWithInlinesView
使用调用表单本身及其内联的forms_valid()
方法将CreateWithInlinesView
子类化为BaseCreateWithInlinesView
。在相关问题 更多 >
编程相关推荐