Issue
Is it possible to index only the date aspect of a models.DateTimeField in Django?
I cant seem to find it in the documentation, and i'm not sure if doing something like this works
class Meta:
indexes = [
models.Index(fields=['created_at__year', 'created_at__month', 'created_at__day']),
]
Solution
This answer shows how to do it in Postgres. However, Django's indexes don't support this out of the box. You'll need to manage it yourself via migrations.RunSQL
.
migrations.RunSQL(
"CREATE INDEX foo_created_at_date_idx ON event ((created_at::DATE));",
"DROP INDEX IF EXISTS foo_created_at_date_idx;",
)
Answered By - schillingt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.