我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.db.models.signals.pre_delete()。
def get_media_model(): from django.conf import settings from django.apps import apps try: app_label, model_name = settings.WAGTAILMEDIA_MEDIA_MODEL.split('.') except AttributeError: return Media except ValueError: raise ImproperlyConfigured("WAGTAILMEDIA_MEDIA_MODEL must be of the form 'app_label.model_name'") media_model = apps.get_model(app_label, model_name) if media_model is None: raise ImproperlyConfigured( "WAGTAILMEDIA_MEDIA_MODEL refers to model '%s' that has not been installed" % settings.WAGTAILMEDIA_MEDIA_MODEL ) return media_model # Receive the pre_delete signal and delete the file associated with the model instance.
def get_document_model(): from django.conf import settings from django.apps import apps try: app_label, model_name = settings.WAGTAILDOCS_DOCUMENT_MODEL.split('.') except AttributeError: return Document except ValueError: raise ImproperlyConfigured("WAGTAILDOCS_DOCUMENT_MODEL must be of the form 'app_label.model_name'") document_model = apps.get_model(app_label, model_name) if document_model is None: raise ImproperlyConfigured( "WAGTAILDOCS_DOCUMENT_MODEL refers to model '%s' that has not been installed" % settings.WAGTAILDOCS_DOCUMENT_MODEL ) return document_model # Receive the pre_delete signal and delete the file associated with the model instance.
def remove_record_from_csw(sender, instance, using, **kwargs): """ Delete all csw records associated with the service. We only run on service pre_delete to clean up the csw prior to the django db. """ if instance.type in ["WMS", "OWS"]: for record in instance.servicelayer_set.all(): delete_record(record.uuid) else: delete_record(instance.uuid)
def handle_TiltTempCalibrationPoint_post_save(sender, **kwargs): """ Trigger anything that should happen on update of TiltTempCalibrationPoint """ calibration_point = kwargs.get('instance') calibration_point.sensor.set_redis_reload_flag() # TODO - Add a pre_delete signal to trigger cessation of the relevant tilt_manager process
def delete_file(sender, instance, *args, **kwargs): """ Deletes thumbnail files on `pre_delete` """ if instance.zip_file: if os.path.isfile(instance.zip_file.path): os.remove(instance.zip_file.path)