Skip to content

Instantly share code, notes, and snippets.

@matheusho
Last active October 12, 2024 21:12
Show Gist options
  • Save matheusho/7913118 to your computer and use it in GitHub Desktop.
Save matheusho/7913118 to your computer and use it in GitHub Desktop.
# Import datetime
from datetime import date, timedelta
# date.today() returns the current date
# timedelta(days=X) takes the "days" attribute to subtract days from the current date
date = date.today() - timedelta(days=30)
# The "__gte" lookup search finds records where the date
# is greater than or equal to the comparison value
object_list = Model.objects.filter(date_at__gte=date)
@vbmendes
Copy link

Matheus, acho que você trocou o lookup do seu filtro. Não seria __gte?

@matheusho
Copy link
Author

matheusho commented Dec 11, 2013

Corretíssimo, Vinícius! Falta de atenção no uso do lookup. Corrigido!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment