django admin - 匹配的查询不存在
Posted
技术标签:
【中文标题】django admin - 匹配的查询不存在【英文标题】:django admin - matching query does not exist 【发布时间】:2017-09-30 19:45:09 【问题描述】:编辑 我认为它与 django-fsm 相关,看看我为 States 编写的这段代码
class STATE:
SUBMITTED = 'Submitted'
VERIFIED_BY_DA = 'Verified by DA'
APPROVED_BY_MS = 'Verified by MS'
APPROVED_BY_DR = 'Approved by DR'
APPROVED_BY_SrAO = 'Approved by SAO.'
APPROVED_BY_R = 'Approved by R'
AMOUNT_TRANSFERRED = 'Accepted'
REJECT = 'Rejected'
def __init__(self):
pass
STATE_CHOICES = (
(STATE.SUBMITTED, 'Submitted', 'Medical'),
(STATE.VERIFIED_BY_DA, 'Verified by DA', 'Medical'),
(STATE.APPROVED_BY_MS, 'Approved by MD', 'Medical'),
(STATE.APPROVED_BY_DR, 'Approved by DR', 'Medical'),
(STATE.APPROVED_BY_SrAO, 'Approved by SAO', 'Medical'),
(STATE.APPROVED_BY_R, 'Approved by R', 'Medical'),
(STATE.AMOUNT_TRANSFERRED, 'Amount transferred by AD', 'Medical'),
(STATE.REJECT, 'Reject', 'Medical'),
)
所以我在 django 的模型文件夹下的单独文件中定义了这两个模型 首先,我只定义了 Medical 模型,一切正常
from django_fsm import FSMField
from state import STATE
from state import STATE_CHOICES
class Medical(BaseModel):
general_detail = models.ForeignKey(
GeneralDetail,
help_text='General Detail'
)
state = FSMField(
blank=True,
protected=not settings.DEBUG,
default=STATE.SUBMITTED,
state_choices=STATE_CHOICES,
)
def __str__(self):
return str(self.general_detail.employee.user.first_name) + ' ' \
+ str(self.general_detail.employee.user.last_name)
def __unicode__(self):
return str(self.general_detail.employee.user.first_name) + ' ' \
+ str(self.general_detail.employee.user.last_name)
但是在下面的模型中添加这个之后,当使用 django-admin 保存转换历史中的字段时,它会在 django-admin 中出现错误。
class TransitionHistory(BaseModel):
state_from = FSMField(
blank=True,
protected=not settings.DEBUG,
default=STATE.SUBMITTED,
state_choices=STATE_CHOICES,
)
state_to = FSMField(
blank=True,
protected=not settings.DEBUG,
default=STATE.SUBMITTED,
state_choices=STATE_CHOICES,
)
def __str__(self):
return str(self.state_from) + str(self.state_to)
def __unicode__(self):
return str(self.state_from) + str(self.state_to)
错误 异常类型:DoesNotExist
异常值:医学匹配查询不存在
第 379 行 C:\Python27\lib\site-packages\django\db\models\query.py 在 get self.model._meta.object_name
【问题讨论】:
你能解决你的问题吗?我有类似的东西 嗯,我不记得解决了这个问题,但可能只与迁移有关 【参考方案1】:只需检查您是否进行了迁移,如果是,那么您可能忘记在 admin.py 中注册您的模型
【讨论】:
是的,我已经做了所有事情,我认为它与 django-fsm 模块有关以上是关于django admin - 匹配的查询不存在的主要内容,如果未能解决你的问题,请参考以下文章
在 Django Admin 中保存新对象并发送到 Celery 任务后,匹配查询不存在