Reputation: 11765
I have some tables with quite heavy validation. For convenience I have inlined some of these on related tables. The inlines are intended to be readonly and all the fields are marked readonly. However they are still being validated when you save the page they are inlined into. This is creating some very large page save times. What is a safe way to prevent this behavior? By safe I mean that it's really really important that they aren't accidentally saved without the validation having been run.
Upvotes: 0
Views: 123
Reputation: 11765
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
Upvotes: 2