Fix receiver for pre_delete (#12)

Fix receiver for pre_delete

Signed-off-by: Etzelia <etzelia@hotmail.com>

Reviewed-on: https://git.canopymc.net/Canopy/minecraft_manager/pulls/12
Co-Authored-By: Etzelia <etzelia@hotmail.com>
Co-Committed-By: Etzelia <etzelia@hotmail.com>
roll
Etzelia 2021-07-17 01:55:45 +00:00
parent 9bdacbca75
commit 03608edfae
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)