[Django]-Django post_syncdb signal handler not getting called?

3👍

try putting it in your models.py

👤Paulo

1👍

Just came across the same issue, and the way I solved it was to remove the sender from function arguments and check for it inside the callback function.

from django.db.models import signals
from features import models as features

def create_features(app, created_models, verbosity, **kwargs):
    print "Creating features!"
    if app != features #this will work as it compares models module instances
        return
    # Do stuff...

signals.post_syncdb.connect(create_features)

That way you can keep them in your management module like Django docs suggest. I agree that it should work like you suggested. You could probably dig into the implementation of the Signal class in django.dispatch.

👤djipko

0👍

The point is in the sender. Your custom callback is called only if sender worked out. In my case the sender was db.models and it is not worked out if syncdb called not the first time, i.o. the synced models are exist in database. In the documents it is written, but do not putted a proper emphasis.

sender

The models module that was just installed. That is, if syncdb just installed an app called "foo.bar.myapp", sender will be the foo.bar.myapp.models module.

So my solution was drop the database and install my app again.

👤I159

Leave a comment