Fix receiver for pre_delete

Signed-off-by: Etzelia <etzelia@hotmail.com>
pull/12/head
Etzelia 2021-07-16 20:47:57 -05:00
parent 9bdacbca75
commit 817d2e016e
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
4 changed files with 18 additions and 13 deletions

View File

@ -1,12 +1,7 @@
from django.apps import AppConfig 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): class MinecraftManagerAppConfig(AppConfig):
name = 'minecraft_manager' name = 'minecraft_manager'
verbose_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 import json
from django.contrib.auth.models import User import logging
from django.db.models import Q import os
from os.path import basename import pytz
import logging, yaml, pytz, json, os import yaml
from django.conf import settings
from datetime import datetime 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__) logger = logging.getLogger(__name__)
@ -376,6 +383,11 @@ class Attachment(models.Model):
return self.file.name 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): class IPManager(models.Manager):
def get_queryset(self): def get_queryset(self):
users = User.objects.filter(is_active=True) 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)