我有一个这样的模型
class SnpsPfm(models.Model):
snpid = models.ForeignKey(Snps, models.DO_NOTHING, db_column='SNPID', primary_key=True) # Field name made lowercase.
pfmid = models.ForeignKey(Pfm, models.DO_NOTHING, db_column='PFMID') # Field name made lowercase.
start = models.PositiveIntegerField()
strand = models.PositiveIntegerField()
type = models.CharField(max_length=8)
scoreref = models.FloatField(db_column='scoreRef', blank=True, null=True) # Field name made lowercase.
scorealt = models.FloatField(db_column='scoreALT', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'SNPs_PFM'
unique_together = (('snpid', 'pfmid', 'start', 'strand'),)
def __str__(self):
return str(self.snpid + self.pfmid + self.start + self.strand)
我需要执行此操作
a = SnpsPfm.objects.filter(snpid=qset[0])
score = a[k].scorealt - a[k].scoreref
问题是它不会让我那样给我
could not convert string to float: 'ARNTL.SwissRegulon
我试图将它们强制转换为float,但这显然不是解决方案。我什至尝试添加
def __float__(self):
return float(self.scoreref)
到SnpsPfm,但仍然无法工作