@nonraw_instance
def model_definition_post_save(sender, instance, created, **kwargs):
    model_class = instance.model_class(force_create=True)
    opts = model_class._meta
    db_table = opts.db_table
    if created:
        primary_key = opts.pk
        fields = [(field.get_attname_column()[1], field) for field in opts.fields
                  if field is not primary_key]
        try:
            extra_fields = getattr(instance._state, '_create_extra_fields')
        except __HOLE__:
            pass
        else:
            for column, field in extra_fields:
                remote_field = get_remote_field(field)
                if field.primary_key:
                    assert isinstance(primary_key, models.AutoField)
                    primary_key = field
                elif (remote_field and remote_field.parent_link and
                      isinstance(primary_key, models.AutoField)):
                    field.primary_key = True
                    primary_key = field
                else:
                    fields.append((column, field))
            delattr(instance._state, '_create_extra_fields')
        fields.insert(0, (primary_key.get_attname_column()[1], primary_key))
        try:
            delayed_save = getattr(instance._state, '_create_delayed_save')
        except AttributeError:
            pass
        else:
            for obj in delayed_save:
                obj.model_def = instance
                obj.save(force_insert=True, force_create_model_class=False)
            delattr(instance._state, '_create_delayed_save')
        model_class = instance.model_class(force_create=True)
        perform_ddl('create_model', model_class)
    else:
        old_model_class = instance._model_class
        if old_model_class:
            old_db_table = old_model_class._meta.db_table
            if db_table != old_db_table:
                perform_ddl('alter_db_table', model_class, old_db_table, db_table)
            ContentType.objects.clear_cache()
    instance._model_class = model_class.model
dataset/ETHPy150Open charettes/django-mutant/mutant/management/__init__.py/model_definition_post_save