Fix receiver for pre_delete #12
5
apps.py
5
apps.py
|
@ -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)
|
||||
|
||||
|
|
24
models.py
24
models.py
|
@ -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)
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
def attachment_delete(sender, instance, **kwargs):
|
||||
instance.file.delete(False)
|
Loading…
Reference in New Issue