i want to update a form using only html form i need help please
from django.shortcuts import render, redirect
from .models import Todo
from django.shortcuts import render, get_object_or_404
from django.contrib import messages
# Create your views here.
def create(request):
if request.method == 'POST':
title = request.POST.get('title')
description = request.POST.get('description')
priority = request.POST.get('priority')
completed = request.POST.get('completed')
if completed =='on':
completed=True
else:
completed=False
print('ssssssssssssssssss',completed)
create_todo = Todo.objects.create(title=title, description=description, priority=priority, completed=completed)
# if create_todo.is_valid():
create_todo.save()
return redirect('view_doto')
return render(request, 'home/create.html')
def update(request, id):
postobj= get_object_or_404(Todo, id=id)
if request.method == 'POST':
if request.POST.get('title') and request.POST.get('description') and request.POST.get('priority') and request.POST.get('completed') :
Todo.objects.filter(id = id).update(title= request.POST.get('title'), description= request.POST.get('description'), priority= request.POST.get('priority'), completed= request.POST.get('completed'))
messages.success(request, "The post was successfully updated")
context={'postobj': postobj}
else:
context={'postobj': postobj,'error': 'The post was not successfully updated. The title and content must be filled out.'}
# context={'postobj': postobj}
return render(request, 'home/update.html',context)
def view_doto(request):
posts = Todo.objects.all().order_by('-id')
return render(request, 'home/index.html', {'posts':posts})
this is my views.py
{% extends "base.html" %}
{% block content %}
<div class="header-bar">
<a href="{% url 'view_doto' %}">← Back</a>
</div>
<div class="card-body">
<form method="POST" action="{% url 'create' %}">{% csrf_token %}
<div class="form-outline">
<label class="form-label" for="formControlLg">Title</label>
<input type="text" name="title" value="{{ postobj.title }}" class="form-control form-control-lg" />
</div>
<div class="form-outline">
<label class="form-label" for="formControlDefault">Description</label>
<input type="text" name="description" value="{{ postobj.description}}" class="form-control" />
</div>
<div class="form-outline">
<label class="form-label" for="typeNumber">Priority</label>
<input type="number" name="priority" value="{{postobj.priority}}" class="form-control" />
</div><br>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="{{ postobj.completed}}" name="completed"> Completed
<!-- <label class="form-check-label" for="flexCheckDefault"> -->
</label>
</div>
<br>
<input class="button" type="submit" value="search">
</form>
</div>
{% endblock content%}
this is the template for the update…please how can i fix this i eed help