Djangoextraviews了解最新美国

2024-05-15 11:59:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用来自django-extra-viewsCreateWithInlinesView。在这种情况下,如何检索当前用户?在

我现在有这样的东西

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")的错误。在

编辑:把我的编辑变成一个答案


Tags: django用户selfform编辑by情况extra
1条回答
网友
1楼 · 发布于 2024-05-15 11:59:05
    def forms_valid(self, form, inlines):
        form.instance.created_by = self.request.user
        return super(PublisherCreateView, self).forms_valid(form, inlines)

这是因为CreateWithInlinesView使用调用表单本身及其内联的forms_valid()方法将CreateWithInlinesView子类化为BaseCreateWithInlinesView。在

相关问题 更多 >