Fix receiver for pre_delete #12

Merged
Etzelia merged 1 commits from refs/pull/12/head into master 2021-07-17 01:55:46 +00:00
4 changed files with 18 additions and 13 deletions

View File

@ -1,12 +1,7 @@
from django.apps import AppConfig
from django.db.models.signals import pre_delete
from minecraft_manager.signals.pre_delete import attachment_delete
class MinecraftManagerAppConfig(AppConfig):
name = 'minecraft_manager'
verbose_name = "Minecraft Manager"
def ready(self):
pre_delete.connect(attachment_delete)

View File

@ -1,10 +1,17 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models import Q
from os.path import basename
import logging, yaml, pytz, json, os
from django.conf import settings
import json
import logging
import os
import pytz
import yaml
from datetime import datetime
from os.path import basename
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q
from django.db.models.signals import pre_delete
from django.dispatch import receiver
logger = logging.getLogger(__name__)
@ -376,6 +383,11 @@ class Attachment(models.Model):
return self.file.name
@receiver(pre_delete, sender=Attachment, dispatch_uid="delete_attachments")
def attachment_delete(sender, instance, **kwargs):
instance.file.delete(False)
class IPManager(models.Manager):
def get_queryset(self):
users = User.objects.filter(is_active=True)

View File

View File

@ -1,2 +0,0 @@
def attachment_delete(sender, instance, **kwargs):
instance.file.delete(False)