[Answer]-Keyword can't be an expression in django model query

1👍

In case of DateTimeField to filter by date you can write something like this:

Model.objects.filter(
  start_date__year=dateobj.year,
  start_date__month=dateobj.month,
  start_date__day=dateobj.day
)

0👍

I think you want to know how to use an expression as a keyword for a named argument. Do this by creating a dictionary (where you can use expressions for keys) then splat it into the method arguments:

kwargs = {
    start_date_date.date(): start_date
}
Model.objects.filter(**kwargs)

But your question is not entirely clear because start_date_date.date() seems wrong anyway.

Leave a comment