models.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.db import models
  2. # Since the test database doesn't have tablespaces, it's impossible for Django
  3. # to create the tables for models where db_tablespace is set. To avoid this
  4. # problem, we mark the models as unmanaged, and temporarily revert them to
  5. # managed during each tes. See setUp and tearDown -- it isn't possible to use
  6. # setUpClass and tearDownClass because they're called before Django flushes the
  7. # tables, so Django attempts to flush a non-existing table.
  8. class ScientistRef(models.Model):
  9. name = models.CharField(max_length=50)
  10. class ArticleRef(models.Model):
  11. title = models.CharField(max_length=50, unique=True)
  12. code = models.CharField(max_length=50, unique=True)
  13. authors = models.ManyToManyField(ScientistRef, related_name='articles_written_set')
  14. reviewers = models.ManyToManyField(ScientistRef, related_name='articles_reviewed_set')
  15. class Scientist(models.Model):
  16. name = models.CharField(max_length=50)
  17. class Meta:
  18. db_tablespace = 'tbl_tbsp'
  19. managed = False
  20. class Article(models.Model):
  21. title = models.CharField(max_length=50, unique=True)
  22. code = models.CharField(max_length=50, unique=True, db_tablespace='idx_tbsp')
  23. authors = models.ManyToManyField(Scientist, related_name='articles_written_set')
  24. reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp')
  25. class Meta:
  26. db_tablespace = 'tbl_tbsp'
  27. managed = False