我有這樣的SQL語句:子查詢選擇where子句
SELECT * FROM result WHERE bet_id IN (SELECT id FROM bet WHERE STATUS="Active")
,這是我的看法:
def manageresult(request):
if 'usid' in request.session:
result = Result.objects.all()
admin = Admin.objects.get(id=request.session['usid'])
return render(request, 'manageresult.html', {'result':result,'admin':admin})
else:
return redirect('login')
如何改變result = Result.objects.all()
到sql語句? 這是賭注模式:
class Bet(models.Model):
status = models.CharField(max_length=20, default="Active")
這是合成模型:
class Result(models.Model):
bet = models.OneToOneField(Bet, on_delete=models.CASCADE)
你能證明你的模型和相關模型領域的方式嗎? – Sayse
@Sayse我在問題 – Krisnadi