models.py 859 B

12345678910111213141516171819202122232425262728
  1. from django.db import connection
  2. from django.db import models
  3. class Article(models.Model):
  4. headline = models.CharField(max_length=100)
  5. pub_date = models.DateTimeField()
  6. class Meta:
  7. index_together = [
  8. ["headline", "pub_date"],
  9. ]
  10. # Model for index_together being used only with single list
  11. class IndexTogetherSingleList(models.Model):
  12. headline = models.CharField(max_length=100)
  13. pub_date = models.DateTimeField()
  14. class Meta:
  15. index_together = ["headline", "pub_date"]
  16. # Indexing a TextField on Oracle or MySQL results in index creation error.
  17. if connection.vendor == 'postgresql':
  18. class IndexedArticle(models.Model):
  19. headline = models.CharField(max_length=100, db_index=True)
  20. body = models.TextField(db_index=True)
  21. slug = models.CharField(max_length=40, unique=True)