1 from django
.db
import models
3 # Since the test database doesn't have tablespaces, it's impossible for Django
4 # to create the tables for models where db_tablespace is set. To avoid this
5 # problem, we mark the models as unmanaged, and temporarily revert them to
6 # managed during each test. We also set them to use the same tables as the
7 # "reference" models to avoid errors when other tests run 'syncdb'
8 # (proxy_models_inheritance does).
10 class ScientistRef(models
.Model
):
11 name
= models
.CharField(max_length
=50)
13 class ArticleRef(models
.Model
):
14 title
= models
.CharField(max_length
=50, unique
=True)
15 code
= models
.CharField(max_length
=50, unique
=True)
16 authors
= models
.ManyToManyField(ScientistRef
, related_name
='articles_written_set')
17 reviewers
= models
.ManyToManyField(ScientistRef
, related_name
='articles_reviewed_set')
19 class Scientist(models
.Model
):
20 name
= models
.CharField(max_length
=50)
22 db_table
= 'tablespaces_scientistref'
23 db_tablespace
= 'tbl_tbsp'
26 class Article(models
.Model
):
27 title
= models
.CharField(max_length
=50, unique
=True)
28 code
= models
.CharField(max_length
=50, unique
=True, db_tablespace
='idx_tbsp')
29 authors
= models
.ManyToManyField(Scientist
, related_name
='articles_written_set')
30 reviewers
= models
.ManyToManyField(Scientist
, related_name
='articles_reviewed_set', db_tablespace
='idx_tbsp')
32 db_table
= 'tablespaces_articleref'
33 db_tablespace
= 'tbl_tbsp'
36 # Also set the tables for automatically created models
38 Authors
= Article
._meta
.get_field('authors').rel
.through
39 Authors
._meta
.db_table
= 'tablespaces_articleref_authors'
41 Reviewers
= Article
._meta
.get_field('reviewers').rel
.through
42 Reviewers
._meta
.db_table
= 'tablespaces_articleref_reviewers'