def field_post_delete(sender, **kwargs): ''' A signal handler to run any pre_save activities and trigger the built-in pre_save signals 1. Update the database with regard to the deleted field 2. Trigger the post delete signal ''' MetaField=sender meta_field=kwargs['instance'] try: # Regenerate our MetaModel, which may have changed DynamicModel = meta_field.meta_model.get_model(regenerate=True, notify_changes=True) utils.unregister_in_admin(admin_site, DynamicModel) utils.remove_from_model_cache(DynamicModel._meta.app_label, DynamicModel.__name__) # Delete field in the database if DYNAMO_DELETE_FIELDS: # TODO: no delete field function available yet pass post_field_update.send(sender=Dynamic_model,field=meta_field) except: pass
def field_post_save(sender, **kwargs): ''' A signal handler to run any post_save activities and trigger the built-in post_save signals 1. Detect renamed fields and run migration 2. Create new fields, if necessary 2. Trigger post creation signal 3. Trigger post update signal ''' MetaField=sender meta_field=kwargs['instance'] try: # Regenerate our MetaModel, which may have changed DynamicModel = meta_field.meta_model.get_model() # If we previously identified a renamed field name, then rename the column if hasattr(meta_field, '_old_name'): utils.rename_db_column(DynamicModel, meta_field._old_name, meta_field.name) del meta_field._old_name # If necessary, add any new columns utils.add_necessary_db_columns(DynamicModel) # Check if the field has just been created if hasattr(meta_field, '_creation'): post_field_creation.send(sender=DynamicModel,new_field=meta_field) del meta_field._creation # Check if the field has just been updated if hasattr(meta_field, '_update'): post_field_update.send(sender=DynamicModel,old_field=meta_field._update,new_field=meta_field) del meta_field._update except ObjectDoesNotExist: return