gpt4 book ai didi

python - Django:TypeError: 'x' 是此函数的无效关键字参数

转载 作者:行者123 更新时间:2023-11-29 06:09:09 25 4
gpt4 key购买 nike

下面的 View 有效,它利用“update_or_create”功能,当某些东西存在并因此更新记录时非常出色。但是,如果它不存在并且必须使用创建选项来创建新记录,我会收到以下错误:

TypeError at /selectteams/1025/3/

'soccerseasonid_id' is an invalid keyword argument for this function

查看下方:

if request.method == 'POST':

form = SelectTwoTeams(request.POST,user=request.user)

if form.is_valid():

teamSelection1, created = UserSelection.objects.update_or_create(user_id=currentUserID,
fixturematchday=fixturematchday,
soccerseason_id=soccerseason,
teamselection1or2=1,
defaults={"campaignno":11,
"teamselection1or2":1,
"teamselectionid_id":request.POST['team1'],
"user_id":currentUserID,
"fixturematchday":fixturematchday,
"soccerseasonid_id":soccerseason})

teamSelection2, created = UserSelection.objects.update_or_create(user_id=currentUserID,
fixturematchday=fixturematchday,
soccerseason_id=soccerseason,
teamselection1or2=2,
defaults={"campaignno":11,
"teamselection1or2":2,
"teamselectionid_id":request.POST['team2'],
"user_id":currentUserID,
"fixturematchday":fixturematchday,
"soccerseasonid_id":soccerseason})

下面的模型:

class StraightredSeason(models.Model):
seasonid = models.IntegerField(primary_key = True)
seasonyear = models.CharField(max_length = 4)
seasonname = models.CharField(max_length = 36)

def __unicode__(self):
return self.seasonid

class Meta:
managed = True
db_table = 'straightred_season'

class UserSelection(models.Model):
userselectionid = models.AutoField(primary_key=True)
campaignno = models.CharField(max_length=36,unique=False)
user = models.ForeignKey(User, related_name='selectionUser')
teamselection1or2 = models.PositiveSmallIntegerField()
teamselectionid = models.ForeignKey('straightred.StraightredTeam', db_column='teamselectionid', related_name='teamID')
fixturematchday = models.IntegerField(null=True)
soccerseason = models.ForeignKey('straightred.StraightredSeason', db_column='soccerseasonid', related_name='fixture_seasonUserSelection')


class Meta:
managed = True
db_table = 'straightred_userselection'

如有任何帮助,我们将不胜感激,非常感谢,Alan。

最佳答案

看起来它使用的是您指定的“soccerseasonid_id”而不是“soccerseason_id”的默认值。 “soccerseason_id”应该有效。

关于python - Django:TypeError: 'x' 是此函数的无效关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39431318/

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