diff --git a/tests/custom_columns/models.py b/tests/custom_columns/models.py index 378a00182011..2ac4f29fdd70 100644 --- a/tests/custom_columns/models.py +++ b/tests/custom_columns/models.py @@ -34,7 +34,7 @@ def __str__(self): class Article(models.Model): Article_ID = models.AutoField(primary_key=True, db_column="Article ID") headline = models.CharField(max_length=100) - authors = models.ManyToManyField(Author, db_table="my_m2m_table") + authors = models.ManyToManyField("Author", through="ArticleAuthor") primary_author = models.ForeignKey( Author, models.SET_NULL, @@ -48,3 +48,12 @@ class Meta: def __str__(self): return self.headline + + +class ArticleAuthor(models.Model): + article = models.ForeignKey(Article, on_delete=models.CASCADE) + author = models.ForeignKey(Author, on_delete=models.CASCADE) + + class Meta: + unique_together = (('article', 'author'),) + db_table = "my_m2m_table" diff --git a/tests/custom_columns/tests.py b/tests/custom_columns/tests.py index 1b211b4c0946..849b0559a649 100644 --- a/tests/custom_columns/tests.py +++ b/tests/custom_columns/tests.py @@ -34,7 +34,7 @@ def test_filter_first_name(self): def test_field_error(self): msg = ( "Cannot resolve keyword 'firstname' into field. Choices are: " - "Author_ID, article, first_name, last_name, primary_set" + "Author_ID, article, articleauthor, first_name, last_name, primary_set" ) with self.assertRaisesMessage(FieldError, msg): Author.objects.filter(firstname__exact="John") @@ -81,7 +81,7 @@ def test_author_get(self): def test_filter_on_nonexistent_field(self): msg = ( "Cannot resolve keyword 'firstname' into field. Choices are: " - "Author_ID, article, first_name, last_name, primary_set" + "Author_ID, article, articleauthor, first_name, last_name, primary_set" ) with self.assertRaisesMessage(FieldError, msg): Author.objects.filter(firstname__exact="John") diff --git a/tests/datetimes/models.py b/tests/datetimes/models.py index 9c8e5e6cd9d9..3e1934b47002 100644 --- a/tests/datetimes/models.py +++ b/tests/datetimes/models.py @@ -5,8 +5,7 @@ class Article(models.Model): title = models.CharField(max_length=100) pub_date = models.DateTimeField() published_on = models.DateField(null=True) - - categories = models.ManyToManyField("Category", related_name="articles") + categories = models.ManyToManyField("Category", related_name="articles", through="ArticleCategory") def __str__(self): return self.title @@ -24,3 +23,13 @@ def __str__(self): class Category(models.Model): name = models.CharField(max_length=255) + + +class ArticleCategory(models.Model): + article = models.ForeignKey(Article, on_delete=models.CASCADE) + category = models.ForeignKey(Category, on_delete=models.CASCADE) + + class Meta: + unique_together = (('article', 'category'),) + db_table = "datetimes_article_category" + \ No newline at end of file