7

Haystack

haystack_signal_processor let you use custom signal processor to initiate index for certain models.

I have in my settings.py

HAYSTACK_SIGNAL_PROCESSOR='my_app.signals.MySignalProcessor'
(this imports signals.py so. this is settings -> signals)

then inside my signals.py I have
from my_app.models import my_model # to connect my_model
And my_app.models.py has from django.conf import settings
(signals -> models -> settings)

How do I resolve this circular import?

eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

5

taken from https://github.com/PitonFoundation/atlas/commit/cc0abcb

Instead of importing the model on top of your signals.py file, import the models in the methods of your custom SignalProcessor using get_model:

from django.db.models.loading import get_model

class MySignalProcessor(signals.BaseSignalProcessor):
    def setup(self):
        MyModel = get_model('myApp', 'MyModel')
        models.signals.post_save.connect(self.handle_save, sender=MyModel)
Michael
  • 731
  • 1
  • 7
  • 11