parameters: (self, **kwargs)
docstring: Adds, validates and persist formsets
docstring_summary: Adds, validates and persist formsets
docstring_tokens: Adds validates and persist formsets
function: def handle(self, **kwargs):
          """Adds, validates and persist formsets"""
          instruction = next(iter(filter(
              lambda key: 'add-' in key, self.request.POST)), None)
  
          # Handle adding related instance
  
          if instruction:
              formsets = get_formsets(self.operation, **kwargs)
              return self.add(formsets, instruction)
  
          # Validate and save form/formsets
  
          formsets = []
  
          for formset in self.formsets:
              formsets.append(formset(
                  self.request.POST,
                  instance=self.instance,  # None for create operation
                  prefix=formset.form.__name__
              ))
  
          if self.form.is_valid() and all(
              formset.is_valid() for formset in formsets
          ):
              return self.save(formsets, **kwargs)
          else:
              return self.report(formsets)
function_tokens: def handle ( self , * * kwargs ) : instruction = next ( iter ( filter ( lambda key : 'add-' in key , self . request . POST ) ) , None ) # Handle adding related instance if instruction : formsets = get_formsets ( self . operation , * * kwargs ) return self . add ( formsets , instruction ) # Validate and save form/formsets formsets = [ ] for formset in self . formsets : formsets . append ( formset ( self . request . POST , instance = self . instance , # None for create operation prefix = formset . form . __name__ ) ) if self . form . is_valid ( ) and all ( formset . is_valid ( ) for formset in formsets ) : return self . save ( formsets , * * kwargs ) else : return self . report ( formsets )