How to build a TODO App in Django

The main project
The file structure will look something like this.
from django.db import models# Create your models here.class Todoclass(models.Model):    header = models.CharField(max_length=500)    main_text = models.TextField(blank=True)def __str__(self):     return f'{self.header}'
from django import formsfrom .models import Todoclassclass TodoForm(forms.ModelForm):     class Meta:           model = Todoclass           fields=('header','main_text')
from django.contrib import adminfrom .models import Todoclass# Register your models
from django.contrib import adminfrom django.urls import pathfrom Apptodo.views import todo,DeleteWorkurlpatterns = [path('admin/',,path('',todo,name='todo'),path('delete/<pk>/',DeleteWork.as_view(),name='delete'),]
from django.shortcuts import renderimport requestsfrom django.urls import reverse_lazyfrom .models import Todoclassfrom .forms import TodoFormfrom django.views.generic import DeleteView# Create your views here.def todo(request):   form = TodoForm(request.POST or None)   if(request.method=="POST"):   if(form.is_valid()):   form =TodoForm()   objects = Todoclass.objects.all()   count=objects.count()   context={    'form':form,    'work':objects,  'count':count,  }  return render(request,'index.html',context)class DeleteWork(DeleteView):   model = Todoclass   template_name='confirm.html'   success_url=reverse_lazy('todo')
<!doctype html><html lang="en"><head><!-- Required meta tags --><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><!-- Bootstrap CSS --><link href="" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"><title>ToDo</title></head><body><!-- Button trigger modal --><button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">ADD</button><!-- Modal --><div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Modal title</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><form method="POST" action="">{% csrf_token %}<form action="" method="POST">{{form}}<button type="submit">Save</button></form></form></div></div></div></div>{% for item in work %}<div class="container mt-3"><h1>{{item.main_text}}</h1><p>{{}}</p><a href="{% url 'delete' %}"><button type="submit" class="btn btn-danger">DELETE</button></a></div>{% endfor %}<script src="" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script></body></html>
<form method="POST" action="">{% csrf_token %}<p>Are you sure you want to delete? "{{object.header}}"</p><button type="submit" class="btn btn-danger">YES</button></form>




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

You can learn everything about programming from Youtube

Day 24- Minimum Distance of BST

Why is 936p so common on Twitch streams?

12 ways to make your code suck less

The Donkey Kong sprint retrospective


Benefits of Cloud Computing In Business

How to plot MNIST using Matplotlib?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nilay Paul

Nilay Paul

More from Medium

Django Online Store, Series 1

Expenses Tracker App using Django and Pandas.

Build a Django Application To Perform CRUD Operations

A quick introduction to Django