fan*_*err 4 python django django-models django-1.7
我目前正在迁移到Django 1.7.我有一些信号传递未保存的模型实例,现在抛出TypeError: Model instances without primary key value are unhashable.
我想知道Django pre_save信号如何在实例周围传递?我正在查看文档,甚至找到了在1.7(https://github.com/django/django/commit/6af05e7a0f0e4604d6a67899acaa99d73ec0dfaa)中实现此功能的提交,我只是不知道它是如何工作的.
有人可以向我解释pre_save是如何解决这个问题或者我如何绕过这个限制的吗?谢谢.
示例代码如下:
from django.dispatch import Signal
send_text = Signal()
unsaved_model = SomeModel() # note that neither `create` or `.save()` are being called
send_text.send(sender=unsaved_model) # error gets thrown when this gets called
Run Code Online (Sandbox Code Playgroud)
追溯:
File "/home/ubuntu/fangsterr-app/notifications/models.py", line 43, in send
send_text.send(sender=self)
File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 194, in send
if not self.receivers or self.sender_receivers_cache.get(sender) is NO_RECEIVERS:
File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/db/models/base.py", line 484, in __hash__
raise TypeError("Model instances without primary key value are unhashable")
TypeError: Model instances without primary key value are unhashable
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2006 次 |
| 最近记录: |