Skip to content

Instantly share code, notes, and snippets.

@docsallover
Created May 31, 2025 10:54
Show Gist options
  • Save docsallover/fd0669128b3c43b2492ac4f9d00104d5 to your computer and use it in GitHub Desktop.
Save docsallover/fd0669128b3c43b2492ac4f9d00104d5 to your computer and use it in GitHub Desktop.
Db indexing in django using the indexes option within your model's Meta class for more complex or multi-column indexes
class Order(models.Model):
customer_email = models.EmailField()
order_date = models.DateTimeField(auto_now_add=True)
class Meta:
indexes = [
models.Index(fields=['customer_email', 'order_date']), # Composite index
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment