django admin - 匹配查询不存在

时间:2017-05-03 06:04:38

标签: python django django-models django-admin

修改 我认为它与django-fsm有关,看看我为各州编写的代码

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的models文件夹下的单独文件中定义了这两个模型 首先,我只定义了医疗模型,一切正常。

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                 self.model._meta.object_name

1 个答案:

答案 0 :(得分:0)

检查您是否进行了迁移,如果是,那么您可能忘记在admin.py中注册模型