2011-10-14 21:49:43 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
# 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
|
2011-10-15 09:00:31 +00:00
|
|
|
# managed during each test. We also set them to use the same tables as the
|
2013-09-03 15:51:34 +00:00
|
|
|
# "reference" models to avoid errors when other tests run 'migrate'
|
2011-10-15 09:00:31 +00:00
|
|
|
# (proxy_models_inheritance does).
|
2011-10-14 21:49:43 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
class ScientistRef(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
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')
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
class Scientist(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2013-10-22 10:21:07 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
class Meta:
|
2014-06-10 19:35:48 +00:00
|
|
|
db_table = 'model_options_scientistref'
|
2011-10-14 21:49:43 +00:00
|
|
|
db_tablespace = 'tbl_tbsp'
|
|
|
|
managed = False
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
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')
|
2013-10-22 10:21:07 +00:00
|
|
|
|
2011-10-14 21:49:43 +00:00
|
|
|
class Meta:
|
2014-06-10 19:35:48 +00:00
|
|
|
db_table = 'model_options_articleref'
|
2011-10-14 21:49:43 +00:00
|
|
|
db_tablespace = 'tbl_tbsp'
|
|
|
|
managed = False
|
2011-10-15 09:00:31 +00:00
|
|
|
|
|
|
|
# Also set the tables for automatically created models
|
|
|
|
|
2015-02-26 14:19:17 +00:00
|
|
|
Authors = Article._meta.get_field('authors').remote_field.through
|
2014-06-10 19:35:48 +00:00
|
|
|
Authors._meta.db_table = 'model_options_articleref_authors'
|
2011-10-15 09:00:31 +00:00
|
|
|
|
2015-02-26 14:19:17 +00:00
|
|
|
Reviewers = Article._meta.get_field('reviewers').remote_field.through
|
2014-06-10 19:35:48 +00:00
|
|
|
Reviewers._meta.db_table = 'model_options_articleref_reviewers'
|