Step 3: Create folder templates in root directory (same level with todo_main), create home.html inside it
Step 4: Add path of folder templates at field TEMPLATES/DIRS in file settings.py
6. Create app
Step 1: Enter command line with name of app as todo
$ python manage.py startapp todo
Step 2: Declare app todo at field INSTALLED_APPS in file settings.py
Step 3: Define a model Task in todo/models.py
fromdjango.dbimportmodels# Create your models here.classTask(models.Model):
task=models.CharField(max_length=250)
is_completed=models.BooleanField(default=False)
# Recommend to use for every model, because it's very important while storing the big data in database.# Can see when data was created and modified previouslycreated_at=models.DateTimeField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)
# Set a string representation of this modeldef__str__(self):
returnself.task
Step 4: Register model inside todo/admin.py
fromdjango.contribimportadminfrom .modelsimportTask# Register your models here.admin.site.register(Task)
Step 5: Enter command line to makemigrate and migrate new model to database (Very important when define new model)
9. Create add_task function and activate CSRF token
Step 1: Define path in todo_main/urls.py
Step 2: In todo, create new file urls.py and add an API
Step 3: In todo/views.py, create function is called by todo/urls.py
Step 4: Change some fields to get data from form
Step 5: Activate CSRF token to secure (Very important, always activate CSRF token with POST method)
10. Mark as done
Step 1: Add API mark-as-done in todo/urls.py
Step 2: In todo/views.py, create function is called by todo/urls.py
Step 3: In file templates/home.html, at anchor tag which has href, add name of API here
<ahref="{% url 'mark_as_done' incompleted_task.pk %}" class="btn btn-success"><iclass="fa fa-check"></i> Mark as Done</a>
11. Edit task
Step 1: Add API edit_task in todo/urls.py
Step 2: In todo/views.py, create function is called by todo/urls.py
Step 3: In file templates/home.html, at anchor tag which has href, add name of API here
Step 4: In edit_task function, define 2 logic, one for GET method to get info current task, other for POST method to assign value new task to current task for updating purpose