📌  相关文章
📜  如何在 django 中在基于类的视图中形成 .cleaned 数据 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:26.693000             🧑  作者: Mango

代码示例1
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.edit import CreateView
from myapp.models import Author

class AuthorCreateView(LoginRequiredMixin, CreateView):
    model = Author
    fields = ['name']

    def form_valid(self, form):
        form.instance.created_by = self.request.user
        return super().form_valid(form)