Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda