Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/custom_columns/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
4 changes: 2 additions & 2 deletions tests/custom_columns/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 11 additions & 2 deletions tests/datetimes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Loading