2

django models 自定义方法报错,我这哪里写的有问题?

 2 years ago
source link: https://www.v2ex.com/t/849243
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

django models 自定义方法报错,我这哪里写的有问题?

  maloneleo88 · 6 小时 30 分钟前 · 306 次点击
.....


class Detect(models.Model):
    def chioce_id(self):
        data = self.objects.all()
        id = len(data) + 1
        return id
    detect_id = models.BigIntegerField(verbose_name='编号',default=chioce_id)
    .......

为什么一直报我错呢? 我想弄个可自填可手改的序号, 这方法在类里不能用吗?有别的法吗?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK