如何为Django模型BooleanField添加布尔按钮,以便普通用户可以将值设置为true或false?

我正在制作一个“任务管理待办” Web应用程序。我的代码正在运行,达到用户登录后可以添加任务的级别,并且该任务连同外键用户都存储到UserTask Model中,其中包含4个字段,其中包括User(FK) ,标签,到期日,状态(布尔值)。用户添加任务时输入了最后三个字段,但是我需要我的状态字段(该字段连同其他字段一起显示在task.html中),以便可以在true或false(任务完成与否)之间切换checkList最好。

我如何在Django 3中做到这一点?

我的models.py,forms.py,views.py和task.html如下:

models.py

from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
# Create your models here.

class UserCustom(models.Model):
    user=models.OneToOneField(User,on_delete=models.CASCADE)

    profile_pic=models.ImageField(upload_to='profile_pics',blank=True)

    def __str__(self):
        return self.user.username   #user os object defined above

class UserTask(models.Model):
    author = models.ForeignKey(User,on_delete=models.CASCADE)
    label=models.CharField(max_length=264)
    date=models.DateField()
    status=models.BooleanField(default=False)

    def __str__(self):
        return str(self.label)

表格

from django import forms
from django.forms.fields import DateField
from django.contrib.auth.models import User
from taskApp.models import UserCustom,UserTask
from django.contrib.admin.widgets import AdminDateWidget

class UserForm(forms.ModelForm):
    password=forms.CharField(widget=forms.PasswordInput())

    class Meta():
        model=User
        fields=('username','email','password')

class UserCustomForm(forms.ModelForm):
    class Meta():
        model=UserCustom
        fields=('profile_pic',)

class UserTaskForm(forms.ModelForm):
    date=DateField(widget=forms.DateInput(attrs={'placeholder': 'YYYY-MM-DD', 'required': 'required'}))
    class Meta():
        model=UserTask
        fields=('label','date','status')

views.py

from django.shortcuts import render
from taskApp.forms import UserForm,UserCustomForm,UserTaskForm
from taskApp.models import UserCustom,UserTask
#below libraries required for login
from django.contrib.auth import authenticate,login,logout
from django.http import HttpResponseRedirect,HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required

# Create your views here.
def index(request):
    return render(request,'taskApp/index.html')

@login_required
def add_task(request):
    added=False

    if request.method == "POST":
        task_form=UserTaskForm(data=request.POST)

        if task_form.is_valid():
            task=task_form.save(commit=False)
            #print("NAME:"+str(request.user))
            task.author=request.user
            task.save()
            added=True

        else:
            print(task_form.errors)


    else: #no request=POST yet
        task_form=UserTaskForm()

    return render(request,'taskApp/addTask.html',{'added':added,'task_form':task_form})

@login_required
def my_task(request):
    task_obj=UserTask.objects.filter(author=request.user)
    return render(request,'taskApp/task.html',{'task_obj':task_obj})


@login_required
def user_logout(request):  #only login users can logout
    logout(request)
    return HttpResponseRedirect(reverse('index'))


def register(request):

    registered=False

    if request.method == "POST":

        user_form=UserCustomForm(data=request.POST)
        profile_form=UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user=user_form.save()
            user.set_password(user.password)
            user.save()

            profile=profile_form.save(commit=False)
            profile.user=user

            if 'profile_pic' in request.FILES:
                profile.profile_pic=request.FILES['profile_pic']

            profile.save()
            registered=True

        else:
            print(user_form.errors,profile_form.errors)

    else: #no request=POST yet
        user_form=UserCustomForm()
        profile_form=UserProfileInfoForm()

    return render(request,'taskApp/registration.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered })



def user_login(request):

    if request.method=='POST':
        username=request.POST.get('username')  #name of element
        password=request.POST.get('password')

        user=authenticate(username=username,password=password)

        if user:
            if user.is_active:
                login(request,user)
                return HttpResponseRedirect(reverse('taskApp:myTask')) #myTask is the name of url , go to urls.py
            else:
                return HttpResponse("ACCOUNT NOT ACTIVE")

        else:
            print("Someone tried to login and failed!")
            print("Username: {} and password {}".format(username,password))
            return HttpResponse("invalid login details supllied!")

    else:
        return render(request,'taskApp/login.html',{})

task.html

{% extends "taskApp/base.html" %}
{% load static %}
{% block body_block %}
<div class="jumbotron">
  {% if task_obj %}
      <table>
          <thead>
              <th>Label</th>
              <th>Due Date</th>
              <th>Status</th>
          </thead>
          {% for t in task_obj %}
            <tr>
                <td>{{ t.label }}</td>
                <td>{{ t.date }}</td>
                <td>{{ t.status }}</td>
            </tr>
          {% endfor %}
      </table>
  {% else %}
      <p>NO TASKS FOUND</p>
  {% endif %}

</div>

{% endblock %}