Skip to content

Commit

Permalink
Add index on product model
Browse files Browse the repository at this point in the history
  • Loading branch information
IKarbowiak committed May 30, 2023
1 parent ac70e7c commit 3911583
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import migrations, models


class Migration(migrations.Migration):
atomic = False

dependencies = [
("product", "0008_merge_20230527_0946"),
]

operations = [
AddIndexConcurrently(
model_name="product",
index=models.Index(fields=["name", "slug"], name="product_index"),
)
]
7 changes: 7 additions & 0 deletions zerodowntime/zerodowntime/product/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.db.models import Index


class Product(models.Model):
Expand All @@ -10,6 +11,12 @@ class Product(models.Model):

class Meta:
ordering = ("pk",)
indexes = [
Index(
name="product_index",
fields=["name", "slug"],
),
]

def __str__(self) -> str:
return self.name

0 comments on commit 3911583

Please sign in to comment.