无法创建一致的方法解析:SingleObjectMixin,DeletionMixin

时间:2017-06-02 11:35:43

标签: django

Django 1.11.1

你能看看回溯吗?

我无法理解干扰SingleObjectMixin和DeletionMixin中的内容。

你能帮我一把吗?

回溯:

  File "/home/michael/PycharmProjects/photoarchive_2/photoarchive/frameplaces/views.py", line 53, in <module>
    DeleteView):
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, SingleObjectMixin, DeletionMixin

class FramePlaceDelete(SubmodelDeleteHistoryMixin,
                       DeleteView):

    model = FramePlace


class SubmodelDeleteHistoryMixin(GeneralHistoryMixin,
                                 DeletionMixin):

    operation = "-"  # For FramePlaceHistoryMixin.

    def delete(self, request, *args, **kwargs):
        # DeleteView differs from CreateView and UpdateView:
        # it doesn't validate the form.
        # And we also need the object in save_history().

        self.object = self.get_object()
        super(SubmodelDeleteHistoryMixin, self).save_history()
        success_url = self.get_success_url()
        self.object.delete()
        return HttpResponseRedirect(success_url)

稍后添加:

class GeneralHistoryMixin(ModelFormMixin):
    """
    For some objects we need history.      

    """
    operation = "+"

    def save_history(self):
        pass # Override it every time in subclasses.

    def form_valid(self, form):
        self.object = form.save()
        if form.has_changed():
            self.save_history() # The method form_valid is redefined for this very string.
                                # string.
        return HttpResponseRedirect(self.get_success_url())

0 个答案:

没有答案