Skip to content
Advertisement

Update model field ( SearchVector ) using signals.py

I am trying to update search vector field using post_save signal. Through “Admin.py”, It is working perfectly, but through “Form page” , the searchVector field or any other field is not getting updated. In form page, I have many to many field – “Tag” that I save through “form.save_m2m” method Please review my code and suggest .. https://dpaste.org/ujPi Thanks in advance

JavaScript

Advertisement

Answer

Just to be absolutely sure, everything is saving perfectly but your signals are not being called, right?

This is solvable by adding 2 lines of code inside the apps.py file (which should live at the same depth as your models.py file). For example, if the application (or the folder containing models.py) is called “jobs” and create_profile is inside the file named signals.py you should modify the apps.py file like this:

JavaScript

Django only finds some files “magically” when it expects their names (like models.py, management/commands, etc) but not the signals.py (or the name of the file where create_profile exists). The fix in the snippet is not “pretty”, but you should do the import inside the ready method as django might call signals.py twice if it is imported somewhere else.

PD. If this works for you, please let me know if you get a “Joined field references are not permitted in this query” error when saving (the reason I found this question) is because Django-Taggit + SearchVector inside the same model raises this error

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement