4

I have configured some django signals on the pre_delete, post_save and pre_delete receivers for some models which are stored in a signals.py file in the same package as the models.

Saving from an API call or directly in the terminal triggers the signals but when saving from the Admin dashboard they are not fired. I have imported the signals in the ready() method of the AppConfig which changes nothing.

Any help on this issue?

PS: Using django-oscar if that helps.

from django.db.models.signals import post_delete, post_save, pre_delete

from django.dispatch import receiver

from oscar.core.loading import get_model

MyModel = get_model('mypackage', 'MyModel')

@receiver(post_save, sender=MyModel)
def do_stuff(sender, instance=None, created=False, **kwargs):
    update_stuff()
isaiah
  • 51
  • 3
  • Pls post your model and related code to help – Vinay P May 30 '18 at 12:20
  • Added a snippet to show the organisation, `update_stuff()` never gets called when saving from the admin – isaiah May 30 '18 at 12:31
  • What do you mean by "admin dashboard" - is that the Django admin or the Oscar dashboard? If Oscar dashboard then how have you made your model editable through the dashboard? – solarissmoke May 30 '18 at 12:48
  • It's the default django admin interface, not the oscar dashboard. The models are registered using the default `admin.ModelAdmin` from django. – isaiah May 30 '18 at 13:03
  • 1
    Does the ready() method of your AppConfig get used by the Django Admin app? I assume it doesn't? – zubhav May 30 '18 at 13:12
  • I don't suppose it does, just trying all possible options. Is there a way to explicitly load the signals in the Django Admin App? – isaiah May 30 '18 at 13:41

1 Answers1

0

had a similar problem. My Problem was to upload the image to some other destination once the model is saved though admin. Solved it by implementing Admin class on admin.py e.g if you have a model namely Shop then in your admin.py would be like

@admin.register(Shop)
class ShopAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        instance = form.instance
        instance.save()
        image_path = instance.banner_image.path
        move_image(image_path)
Haziq Ahmed
  • 87
  • 1
  • 6