django how do i send a post_save signal when updating a user?

你离开我真会死。 提交于 2019-12-05 16:19:46

You should import your signals.py somewhere to run it. For example in models.py.

First, they're called "decorators". Annotations are something else in Django, so best not to confuse terminology there.

The post_save signal is called, as its name implies, after every save. Specifying sender limits the receiver to just post_save signals sent for saves of that particular model. If you leave it out, your receiver will be called when any model is saved, which is surely not what you want.

Your problem here is that your receiver, for all intents and purposes doesn't exist. Django does not import automatically import signals.py for you, so it's never seen. The only way to get it seen is to import it somewhere that Django does look at, such as models.py (as @DrTyrsa) suggests.

However, if you do that, you're going to end up with a circular import error, since you're importing models.py into signals.py already. So, you can either just put your signal code directly into models.py, or find somewhere else to import it; __init__.py might work, but I normally just always put my signals in models.py and call it a day.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!