```python db.delete(mod) for featured in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(featured) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) base_path = os.path.join(secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name)) db.commit() notify_ckan(mod, 'delete') storage = _cfg('storage') if storage: full_path = os.path.join(storage, base_path) rmtree(full_path) ```