Django无法在管理站点中访问模型

时间:2018-08-25 12:22:51

标签: django python-3.x

我试图在我的一个模型中调整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})'

1 个答案:

答案 0 :(得分:0)

由于我的项目不大,所以我决定删除整个数据库,然后从头开始重新设置它。 我使用了this问题的可接受答案

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