我有这个错误:
get() returned more than one model_item -- it returned 2!
抛出此错误的行是:
earray.sort(key=lambda x:"%s" % (x.model_rule.model_item.PRDT_ID.TITLE))
在我的模型下面:
model_rule :
class model_rule(models.Model):
key_id = models.AutoField(primary_key=True)
model_item = models.ForeignKey(model_item,db_column='item_key_id')
def __unicode__(self):
return "%s:%s" % (self.model_item.PRDT_ID.TITLE,self.rule.name)
class Meta:
db_table = 'model_rule'
model_item :
class model_item(models.Model):
ITEM_Id = models.CharField(max_length=64, primary_key=True, db_column = "item_id")
Id = models.CharField(max_length=64, primary_key=True, db_column = "public_id")
category_ID = models.CharField(max_length=64, primary_key=True, db_column="category_ID")
PRDT_ID = models.ForeignKey('PRODUCT', db_column = "product_id")
class Meta:
db_table = 'model_item'
我使用x.model_rule.model_item
的位置很多,我无法逐个更改,所以我需要在category_ID
{{1}列表中添加此过滤器,在模型中进行一次更改每次都避免这个错误
调用过滤器的(17,11,16,15,4,1)
或model_rule.model_item
已添加到查询中。