original_docstring: 
          Allows to change Level id from Admin form.
          It will migrate all dives using these levels to the new id.
          
docstring: Allows to change Level id from Admin form.
  It will migrate all dives using these levels to the new id.
docstring_tokens: Allows to change Level id from Admin form . It will migrate all dives using these levels to the new id .
code: def save_model(self, request, obj, form, change):
          """
          Allows to change Level id from Admin form.
          It will migrate all dives using these levels to the new id.
          """
          self.oldid = None
  
          # Nominal case. No migration.
          if form.oldid is None or form.oldid == form.newid:
              obj.save()
              return
  
          with transaction.atomic():
              # Migrate Dives
              migrated = []
              for t in Dive.objects.filter(levels__in=[form.oldid]):
                  t.levels.remove(Level.objects.get(id=form.oldid))
                  t.save()
                  migrated.append(t)
              # Apply id change
              self.oldid = form.oldid
              obj.save()  # Will create new row in DB
              old = Level.objects.get(id=self.oldid)
              old.delete()
              # Restore
              for t in migrated:
                  t.levels.add(obj)
                  t.save()
code_tokens: def save_model ( self , request , obj , form , change ) : self . oldid = None if form . oldid is None or form . oldid == form . newid : obj . save ( ) return with transaction . atomic ( ) : migrated = [ ] for t in Dive . objects . filter ( levels__in = [ form . oldid ] ) : t . levels . remove ( Level . objects . get ( id = form . oldid ) ) t . save ( ) migrated . append ( t ) self . oldid = form . oldid obj . save ( ) old = Level . objects . get ( id = self . oldid ) old . delete ( ) for t in migrated : t . levels . add ( obj ) t . save ( )
short_docstring: Allows to change Level id from Admin form.
short_docstring_tokens: Allows to change Level id from Admin form .
comment: """
          Allows to change Level id from Admin form.
          It will migrate all dives using these levels to the new id.
          """$SEP$# Nominal case. No migration.$SEP$# Migrate Dives$SEP$# Apply id change$SEP$# Will create new row in DB$SEP$# Restore