

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from wger.gym.models import Gym
from wger.gym.models import GymConfig


@receiver(post_save, sender=Gym)
def gym_config(sender, instance, created, **kwargs):
    '''
    Creates a configuration entry for newly added gyms
    '''
    if not created or kwargs['raw']:
        return

    config = GymConfig()
    config.gym = instance
    config.save()



from django.conf import settings
from django.db.models.signals import post_save
from django.db.models.signals import post_delete
from django.dispatch import receiver

from wger.gym.models import Gym
from wger.gym.models import GymConfig
from wger.gym.models import UserDocument


@receiver(post_save, sender=Gym)
def gym_config(sender, instance, created, **kwargs):
    '''
    Creates a configuration entry for newly added gyms
    '''
    if not created or kwargs['raw']:
        return

    config = GymConfig()
    config.gym = instance
    config.save()


@receiver(post_delete, sender=UserDocument)
def delete_user_document_on_delete(sender, instance, **kwargs):
    '''
    Deletes the document from the disk as well
    '''

    instance.document.delete(save=False)

Delete the document from the disk on delete
Delete the document from the disk on delete

  
  
  from django.conf import settings
  from django.db.models.signals import post_save
+ from django.db.models.signals import post_delete
  from django.dispatch import receiver
  
  from wger.gym.models import Gym
  from wger.gym.models import GymConfig
+ from wger.gym.models import UserDocument
  
  
  @receiver(post_save, sender=Gym)
  def gym_config(sender, instance, created, **kwargs):
      '''
      Creates a configuration entry for newly added gyms
      '''
      if not created or kwargs['raw']:
          return
  
      config = GymConfig()
      config.gym = instance
      config.save()
  
+ 
+ @receiver(post_delete, sender=UserDocument)
+ def delete_user_document_on_delete(sender, instance, **kwargs):
+     '''
+     Deletes the document from the disk as well
+     '''
+ 
+     instance.document.delete(save=False)
+ 
Delete the document from the disk on delete
## Code Before:


from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from wger.gym.models import Gym
from wger.gym.models import GymConfig


@receiver(post_save, sender=Gym)
def gym_config(sender, instance, created, **kwargs):
    '''
    Creates a configuration entry for newly added gyms
    '''
    if not created or kwargs['raw']:
        return

    config = GymConfig()
    config.gym = instance
    config.save()

## Instruction:
Delete the document from the disk on delete
## Code After:


from django.conf import settings
from django.db.models.signals import post_save
from django.db.models.signals import post_delete
from django.dispatch import receiver

from wger.gym.models import Gym
from wger.gym.models import GymConfig
from wger.gym.models import UserDocument


@receiver(post_save, sender=Gym)
def gym_config(sender, instance, created, **kwargs):
    '''
    Creates a configuration entry for newly added gyms
    '''
    if not created or kwargs['raw']:
        return

    config = GymConfig()
    config.gym = instance
    config.save()


@receiver(post_delete, sender=UserDocument)
def delete_user_document_on_delete(sender, instance, **kwargs):
    '''
    Deletes the document from the disk as well
    '''

    instance.document.delete(save=False)
