0

我有一些经过大量验证的表。为方便起见,我在相关表格中内联了其中一些。内联是只读的,所有字段都标记为只读。但是,当您保存它们内联到的页面时,它们仍在被验证。这会创建一些非常大的页面保存时间。什么是防止这种行为的安全方法?所谓安全,我的意思是非常重要的是,在没有运行验证的情况下不会意外保存它们。

4

1 回答 1

2

This is what I have so far, it makes sense and seems to work:

class ReadOnlyInlineFormSet(BaseInlineFormSet):
    """ This inline can't save and subsequently doesn't need to validate """

    def save(self, commit=True):
        self.new_objects = []
        self.changed_objects = []
        self.deleted_objects = []
        return []

    def is_valid(self):
        return True

And then in the each inline:

formset = ReadOnlyInlineFormSet
于 2013-01-23T15:24:54.243 回答