diff options
| author | Moayad Mardini <moayad.m@gmail.com> | 2014-06-10 22:35:48 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-06-11 11:40:08 -0400 |
| commit | 7bd2ad1dd9fc449ed1b4832fab5c975d7c8aa895 (patch) | |
| tree | adeecba68247fcb6ca7525af3f05442397eb467d /tests/model_options/models/tablespaces.py | |
| parent | 1ff11304dcebbabdede8ef3d659ca0e54055e2fd (diff) | |
[1.7.x] Created a new tests folder (`model_options`).
And moved `tablespaces` option tests to it.
The new folder can be used to test models/options, like the new option
added in refs #22778.
Backport of 5a3ae7e260 from master
Diffstat (limited to 'tests/model_options/models/tablespaces.py')
| -rw-r--r-- | tests/model_options/models/tablespaces.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/model_options/models/tablespaces.py b/tests/model_options/models/tablespaces.py new file mode 100644 index 0000000000..56e22e973a --- /dev/null +++ b/tests/model_options/models/tablespaces.py @@ -0,0 +1,48 @@ +from django.db import models + +# Since the test database doesn't have tablespaces, it's impossible for Django +# to create the tables for models where db_tablespace is set. To avoid this +# problem, we mark the models as unmanaged, and temporarily revert them to +# managed during each test. We also set them to use the same tables as the +# "reference" models to avoid errors when other tests run 'migrate' +# (proxy_models_inheritance does). + + +class ScientistRef(models.Model): + name = models.CharField(max_length=50) + + +class ArticleRef(models.Model): + title = models.CharField(max_length=50, unique=True) + code = models.CharField(max_length=50, unique=True) + authors = models.ManyToManyField(ScientistRef, related_name='articles_written_set') + reviewers = models.ManyToManyField(ScientistRef, related_name='articles_reviewed_set') + + +class Scientist(models.Model): + name = models.CharField(max_length=50) + + class Meta: + db_table = 'model_options_scientistref' + db_tablespace = 'tbl_tbsp' + managed = False + + +class Article(models.Model): + title = models.CharField(max_length=50, unique=True) + code = models.CharField(max_length=50, unique=True, db_tablespace='idx_tbsp') + authors = models.ManyToManyField(Scientist, related_name='articles_written_set') + reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp') + + class Meta: + db_table = 'model_options_articleref' + db_tablespace = 'tbl_tbsp' + managed = False + +# Also set the tables for automatically created models + +Authors = Article._meta.get_field('authors').rel.through +Authors._meta.db_table = 'model_options_articleref_authors' + +Reviewers = Article._meta.get_field('reviewers').rel.through +Reviewers._meta.db_table = 'model_options_articleref_reviewers' |
