从已弃用的Djang版本更新身份验证模型

2024-06-28 14:32:57 发布

您现在位置:Python中文网/ 问答频道 /正文

在 我有以下不推荐使用的代码:

class samberos(User):
    objects = UserManager()
    backstage = models.BooleanField(default=False, help_text="Si el sambero esta activo, pero no tocando instrumentos ... ")
    dni = models.CharField(max_length=10, blank=True, null=True)
    phone = models.CharField(max_length=9, blank=True, null=True)
    movil = models.CharField(max_length=9, blank=True, null=True, help_text="Este es el numero para los SMS")
    instrumento = models.ForeignKey(instrumentos)
    def url(self):
            return u'<a href="/samberos/' + self.username + u'/" title="' + self.username + u'" rel="gb_page_center[400, 210]">' + self.username + u'</a>'
    class Meta:
            ordering = ['username']
            verbose_name_plural = "samberos"
            verbose_name = "samberos"

我想把它更新到一个新版本的django,目前还不支持,不想失去用户。我该怎么做?在

现在我运行的是1.8版,当我运行服务器时,出现了以下错误:

^{pr2}$

用于创建此代码的django版本是1.2,与1.4配合使用很好


Tags: 代码textselftruemodelsusernamehelpel
1条回答
网友
1楼 · 发布于 2024-06-28 14:32:57

在本例中,我强烈建议将这些字段迁移到UserProfile模型中。在

这是因为django建议将OneToOneFieldUser模型一起使用,而不是继承它(这不仅解决了这个问题,而且将使您符合标准,避免将来的未知问题)。在

documentation about additional fields for users所述:

If you’d like to store additional information related to your users, Django provides a method to specify a site-specific related model – termed a “user profile” – for this purpose.

当然,您需要一个data migration来将旧信息迁移到这个新模型中,但是我可以向您保证,与当前标准保持同步是值得的。在

相关问题 更多 >