1
以下のビューは機能しますが、何かが存在するときにはっきりと "update_or_create"機能を利用しているため、レコードを更新します。それが存在し、新しいレコードを作成するために作成するオプションを使用する必要がありますしない場合は、私は次のエラーを取得する:Django:TypeError: 'x'はこの関数の無効なキーワード引数です
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'
何か助けていただければ幸いです、多くのありがとう、アラン。
とてもシンプルです...私はすぐにどこにput_idにどこのハングを取得します –