gpt4 book ai didi

python - 属性错误 : 'Price' object has no attribute 'update'

转载 作者:行者123 更新时间:2023-12-03 18:25:29 25 4
gpt4 key购买 nike

我收到一个错误,AttributeError: 'Price' object has no attribute 'update' .I 写道

fourrows_transpose=list(map(list, zip(*fourrows)))
val3 = sheet3.cell_value(rowx=0, colx=9)
user3 = Companyransaction.objects.filter(corporation_id=val3).first()
if user3:
area = Area.objects.filter(name="America").first()
pref = Prefecture.objects.create(name="Prefecture", area=area)
city = City.objects.create(name="City", prefecture=pref)
price= Price.objects.create(city=city)

pref.name = fourrows_transpose[0][0]
pref.save()

for transpose in fourrows_transpose[2:]:
if len(transpose) == 5:
if "×" in transpose or "○" in transpose:

city.name = "NY"
city.save()
price.update(upper1000="○",from500to1000="○",under500="○")

在models.py我写
class Area(models.Model):
name = models.CharField(max_length=20, verbose_name='area', null=True)
class User(models.Model):
user_id = models.CharField(max_length=200,null=True)
area = models.ForeignKey('Area',null=True, blank=True)

class Prefecture(models.Model):
name = models.CharField(max_length=20, verbose_name='prefecture')
area = models.ForeignKey('Area', null=True, blank=True)

class City(models.Model):
name = models.CharField(max_length=20, verbose_name='city')
prefecture = models.ForeignKey('Prefecture', null=True, blank=True)
class Price(models.Model):
upper1000 = models.CharField(max_length=20, verbose_name='u1000', null=True)
from500to1000 = models.CharField(max_length=20, verbose_name='500~1000', null=True)
under500 = models.CharField(max_length=20, verbose_name='d500', null=True)
city = models.ForeignKey('City', null=True, blank=True)

我想把“○”放在价格模型的upper1000&from500to1000&under500列,但由于错误而无法完成。我的代码有什么问题?我该如何解决这个问题?

最佳答案

.update是查询集上的方法,而不是模型。如果您想更新一组共享某些查询条件的记录,它会很有用。

更新您已有的对象的正常方法是设置其属性,然后保存它。

price.upper1000 = "○"
price.from500to1000 = "○"
price.under500 = "○"
price.save()

关于python - 属性错误 : 'Price' object has no attribute 'update' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46194898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com