1
0
mirror of https://github.com/django/django.git synced 2024-12-29 12:36:08 +00:00
django/tests/model_indexes/models.py
2022-02-07 20:37:05 +01:00

40 lines
1.0 KiB
Python

from django.db import models
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
pages = models.IntegerField(db_column="page_count")
shortcut = models.CharField(max_length=50, db_tablespace="idx_tbls")
isbn = models.CharField(max_length=50, db_tablespace="idx_tbls")
barcode = models.CharField(max_length=31)
class Meta:
indexes = [
models.Index(fields=["title"]),
models.Index(fields=["isbn", "id"]),
models.Index(
fields=["barcode"], name="%(app_label)s_%(class)s_barcode_idx"
),
]
class AbstractModel(models.Model):
name = models.CharField(max_length=50)
shortcut = models.CharField(max_length=3)
class Meta:
abstract = True
indexes = [
models.Index(fields=["name"]),
models.Index(fields=["shortcut"], name="%(app_label)s_%(class)s_idx"),
]
class ChildModel1(AbstractModel):
pass
class ChildModel2(AbstractModel):
pass