<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def handle_dialog(self, *args, **kwargs):
 """Handle form and save and set success message on valid form"""

        form = self.get_form_class()(self.request.POST, initial=kwargs, instance=self.object)

        success_message = None
        if form.is_valid():
            obj = form.save()
            success_message = self.success_message.format(
                model_name=self.get_model_config().model_name.capitalize(),
                object=str(obj),
            )
        return self.display_dialog(*args, form_instance=form, success_message=success_message, **kwargs)