def post(self, request, *args, **kwargs): model_instance = self.get_model_instance() form = OverrideForm.from_model(model_instance, {'data': request.POST}) override_data = self.get_form_data(form) # If we have new data in the form, then save the override if len(override_data) > 0: override = self.get_override() # Create an override object if it doesn't exist if override is None: override = Override.objects.create_from(model_instance) override.data = json.dumps(override_data) override.save() return self.render_to_response(self.get_context_data(form=form))
def post(self, request, *args, **kwargs): model_instance = self.get_model_instance() form = OverrideForm.from_model(model_instance, {'data': request.POST}) override_data = self.get_form_data(form) # If we have new data in the form, then save the override if len(override_data) > 0: override = self.get_override() # Create an override object if it doesn't exist if override is None: override = Override.objects.create_from(model_instance) override.data = json.dumps(override_data) override.save() return self.render_to_response(self.get_context_data(form=form))
def get(self, request, *args, **kwargs): # Check if an override exists. If it does, load it and use its data to populate the form # Get the form override = self.get_override() model_instance = self.get_model_instance() if override is None: # No override exists, show a blank form form_kwargs = None else: # An override exists, so we load it up and use the data as the initial data form_kwargs = {'initial': json.loads(override.data)} form = OverrideForm.from_model(model_instance, form_kwargs) return self.render_to_response(self.get_context_data(form=form))
def get(self, request, *args, **kwargs): # Check if an override exists. If it does, load it and use its data to populate the form # Get the form override = self.get_override() model_instance = self.get_model_instance() if override is None: # No override exists, show a blank form form_kwargs = None else: # An override exists, so we load it up and use the data as the initial data form_kwargs = {'initial': json.loads(override.data)} form = OverrideForm.from_model(model_instance, form_kwargs) return self.render_to_response(self.get_context_data(form=form))