Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
How to get Todo items with today as deadline

so I'm still creating my to-do list app, and I want to render all the items that have today's date as the deadline so as to remind the user of the pending tasks.

models.py

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class ToDo(models.Model):
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
    todo = models.CharField(max_length=50)
    description = models.TextField(max_length=200, blank=True)
    created = models.DateField(auto_now=True)
    end = models.DateField()
    start = models.DateField()
    completed = models.BooleanField(default=False)

    def __str__(self):
        return f'{self.owner} - {self.todo}'

views.py

def index(request):
    activities = ToDo.objects.all()
    today = ToDo.objects.get(end=datetime.date.today)
    todo = ToDo.objects.count()
    complete = ToDo.objects.filter(completed=True).count()
    percent = complete * 100 // todo 
    if request.method == 'POST':
        try:
            search = request.POST.get('todo')
            activities = ToDo.objects.filter(todo__icontains=search)
            
        except:
            search = request.POST.get('end')
            activities = ToDo.objects.filter(end=search)

    context = {
        'activities' : activities,
        'percent' : percent,
        'today' : today,
    }
    return render(request, 'home.html', context)

I imported DateTime in my views.py

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Give this a try

from django.utils import timezone

def index(request):
    today = timezone.localtime(timezone.now())

    deadline_today = ToDo.objects.filter(
        end__year=today.year,
        end__month=today.month,
        end__day=today.day
    )

    context = {
        ...
        'today' : deadline_today ,
    }
over 4 years ago · Santiago Trujillo Report

0

You are almost there!

today = ToDo.objects.get(end=datetime.date.today)

Is the problem. get() is used to fetch a single row, you want all the matching rows which is done by filter. you are also sending in the function today, instead of calling it with today().

Do this:

today = ToDo.objects.filter(end=date.today())
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!