如何在我的views.py中引用OneToOne模型?

时间:2019-01-15 15:07:53

标签: python django django-models django-templates django-views

我不知道如何引用我的OneToOne字段:

class Studente(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    ore = models.IntegerField()

在我的views.py文件中。

@login_required(login_url="/home/")
def vistaPrivata(request):
    all_corsi = Corso.objects.all()
    user = request.user
    user_ore = [[ I Dont really know what to write in here  ]]
    template = loader.get_template('corsi/vistaPrivata.html')
    if request.method == 'POST':
        logout(request)
        return redirect('Completa')
    else:
        context = {
            'user_ore' = user_ore,
        }
        return HttpResponse(template.render(context, request))

能帮我吗? 任何帮助将不胜感激

0 个答案:

没有答案