【问题标题】:Django cannot access model in admin siteDjango 无法访问管理站点中的模型
【发布时间】:2019-01-31 16:36:17
【问题描述】:

我试图在我的一个模型中调整 DateField 以显示时间 (DateTimeField)。我最终还进行了时区调整。毕竟我决定不使用时间并删除附加代码并将字段设置回 DateField。进行迁移并进行迁移。现在,当尝试通过页面或管理页面从模型访问对象时,我收到错误:

invalid literal for int() with base 10: b'24 22:00:00'

所以在尝试了一些事情之后,我只想使用管理页面删除模型中的对象。这也导致了上述错误。

似乎每个依赖于该模型对象的页面都会引发错误。

有没有办法强制删除对象? 你能推荐任何其他的清理方法吗?

模型定义为:

class PieceInstance(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular Piece across whole system')
    piece = models.ForeignKey('Piece', on_delete=models.SET_NULL, null=True) 
    version = models.CharField(max_length=200)
    date_claimed = models.DateField(null=True, blank=True)
    claimant = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    date_sent_to_claimant = models.DateField(null=True, blank=True)

    PIECE_STATUS = (
        ('n', 'Not Claimable'),
        ('a', 'Available'),
        ('r', 'Reserved'),
        ('c', 'Claimed'),
    )

    status = models.CharField(
        max_length=1,
        choices=PIECE_STATUS,
        blank=True,
        default='a',
        help_text='Piece Availability',
    )

    @property
    def claimed_overdue(self):
        days_till_claimed_overdue = 7
        if self.date_claimed and date.today() > self.date_claimed + timedelta(days=days_till_claimed_overdue):
            return True
        return False

    class Meta:
        ordering = ['date_claimed']
        permissions = (('can_mark_sent_to_claimant', 'Set Piece Instance as sent to claimant'),) 

    def __str__(self):
        return f'{self.id} ({self.piece.title})'

【问题讨论】:

    标签: django python-3.x


    【解决方案1】:

    由于我的项目不大,我决定放弃整个数据库并从头开始重新设置。 我使用了this问题的公认答案

    请注意,您还必须重新设置所有用户(包括超级用户)

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 1970-01-01
      • 2018-07-14
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多