Change boolean Django

Asked

Viewed 72 times

0

would like to do an update field that changes the boolean value to true or false inside a modal so you don’t have to create a page just to edit boolean.

I have the following code: in the model

class Tarefa(models.Model):
    titulo = models.CharField(verbose_name="Titulo",max_length=30)
    usuario = models.ForeignKey(User,on_delete=models.PROTECT)
    data_vencimento = models.DateField(verbose_name="Vencimento")
    descricao = models.TextField(verbose_name="Descrição")
    concluido = models.BooleanField(default=False)
    vencido = models.BooleanField(default=False)

in the view

def listTarefa(request):

    tarefas = Tarefa.objects.filter(usuario = request.user).order_by('data_vencimento')
    tarefas_vencidas = []
    tarefas_concluidas=[]
    tarefas_abertas = []


    for tarefa in tarefas:
        if tarefa.concluido:
            tarefas_concluidas.append(tarefa)
        else:

            if date.today() > tarefa.data_vencimento:
                tarefas_vencidas.append(tarefa)
            else:
                tarefas_abertas.append(tarefa)


    return render(request, 'listaTarefas.html', {'tarefas_abertas':tarefas_abertas,'tarefas_vencidas':tarefas_vencidas,
                                                 'tarefas_concluidas':tarefas_concluidas})

on Forms

class ConcluirTarefaForm(forms.ModelForm):
    class Meta:
        model = Tarefa
        fields = ['concluido',]

I am listing the tasks all right but I want to update to change boolean.

inserir a descrição da imagem aqui

as you can see in the image when clicking on the buttom check opens a modal and this modal has to have the form to change the task boolean to true or false.

1 answer

0

I believe that the easiest way to make this change would be via javascript, but you need to see how your form is sent.

  • got in.py views even thanks!.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.