Django在分配给数据库之前获取POST id

时间:2018-05-21 02:49:01

标签: python django

views.py

class Post(CreateView):
    fields = ('title', 'desc')
    model = models.Post

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.desc = self.object.id <---- 
        self.object.save()

        return super(ModelFormMixin, self).form_valid(form)

如何在分配前从帖子中获取对象ID?我尝试使用self.object.id但返回none

0 个答案:

没有答案