[英]Django TypeError(“'%s' is an invalid keyword argument for this function”)
[英]Django: TypeError: 'x' is an invalid keyword argument for this function
當存在某些內容並因此更新一條記錄時,下面的視圖有效地利用了“ update_or_create”功能。 但是,如果它不存在並且必須使用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'
任何幫助將不勝感激,艾倫,謝謝。
看起來它使用的是默認值,其中指定了“ soccerseasonid_id”而不是“ soccerseason_id”。 “ soccerseason_id”應該起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.