Created
April 24, 2020 19:05
-
-
Save susmithagudapati/0da64fec98828715a7d2e2279c635b49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create indexes using Field.db_index value | |
class Product(models.Model): | |
name = models.CharField(max_length=128, db_index=True) | |
upc = models.CharField(max_length=32, unique=True) | |
category = models.ForeignKey( | |
Category, on_delete=models.PROTECT, related_name='categories', null=True) | |
created_by = models.ForeignKey( | |
User, on_delete=models.PROTECT, related_name='product_created_by', null=True) | |
# create indexes using Meta.indexes option | |
class Product(models.Model): | |
name = models.CharField(max_length=128) | |
upc = models.CharField(max_length=32, unique=True) | |
category = models.ForeignKey( | |
Category, on_delete=models.PROTECT, related_name='categories', null=True) | |
created_by = models.ForeignKey( | |
User, on_delete=models.PROTECT, related_name='product_created_by', null=True) | |
class Meta: | |
indexes = [ | |
models.Index(fields=['name'], name='product_name_idx'), | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment