python Django无法分配"&书信电报;Juego:Juego对象>&引用;:&引用;预测.idjuego“;必须是一个";“朱伊戈”;实例
你好,我有以下问题(很抱歉我的英语不好) 我有以下型号 我有3个模型,“Prediccion”有两个外键,分别是“Juego”模型和“Usuario”模型 我有以下观点吗python Django无法分配"&书信电报;Juego:Juego对象>&引用;:&引用;预测.idjuego“;必须是一个";“朱伊戈”;实例,django,django-models,django-views,Django,Django Models,Django Views,你好,我有以下问题(很抱歉我的英语不好) 我有以下型号 我有3个模型,“Prediccion”有两个外键,分别是“Juego”模型和“Usuario”模型 我有以下观点吗 from django.shortcuts import render_to_response from scorecenter.JuegoApp.models import Juego from scorecenter.PrediccionApp.models import Prediccion from scorecent
from django.shortcuts import render_to_response
from scorecenter.JuegoApp.models import Juego
from scorecenter.PrediccionApp.models import Prediccion
from scorecenter.PrediccionApp.models import TipoResultado
from scorecenter.PrediccionApp.models import AuthUser
def juegosap(request, pagina="1", idgame=-1, resa=-1, resb=-1):
if(idgame==-1 and resa==-1 and resb==-1):
pag = int(pagina)
pag = pag-1
lista = Juego.objects.order_by('-fecha', '-id')[pag*4:pag*4+4]
template_name = 'juegos_semana.html'
return render_to_response(template_name,{'lista':lista})
else:
game = Juego.objects.get(id=int(idgame))
print(game.equipoa)
print(game.id)
user = AuthUser.objects.get(username=request.user)
print(user.username)
temporal = Prediccion(idusuario = user, idjuego = game, equipoa=int(resa), equipob=int(resb))
temporal.resultado = 1
temporal.save()
pag = int(pagina)
pag = pag-1
lista = Juego.objects.order_by('-fecha')[pag*4:pag*4+4]
template_name = 'juegos_semana.html'
return render_to_response(template_name,{'lista':lista})
但我得到了以下错误:
Cannot assign "<Juego: Juego object>": "Prediccion.idjuego" must be a "Juego" instance.
in the next line:
temporal = Prediccion(idusuario = user, idjuego = game, equipoa=int(resa), equipob=int(resb))
无法分配“”:“Prediccion.idjuego”必须是“Juego”实例。
在下一行:
时间=预测(idusuario=用户,idjuego=游戏,equipoa=整数(resa),equipob=整数(resb))
您的idjuego是一个外键,因此该值必须等于id
尝试:
另外,在每个模型中,请输入unicode,使其不会返回“