summaryrefslogtreecommitdiff
path: root/tests/validation
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-06-25 10:28:52 +0200
committerCarlton Gibson <carlton@noumenal.es>2020-06-25 11:36:20 +0200
commite13cfc6dfd4212ef7a40db1a41d3ae6ac4b97de0 (patch)
treeb1c18b05bb10b84be3b5842855ba95c386157c32 /tests/validation
parent1e96de4f974acbdaa25ad4ba1894ea060213174e (diff)
Fixed #31596 -- Changed ForeignKey.validate() to use the base manager.
Diffstat (limited to 'tests/validation')
-rw-r--r--tests/validation/models.py9
-rw-r--r--tests/validation/tests.py7
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/validation/models.py b/tests/validation/models.py
index 47fb895ec5..ff9aad11f0 100644
--- a/tests/validation/models.py
+++ b/tests/validation/models.py
@@ -74,8 +74,17 @@ class CustomMessagesModel(models.Model):
)
+class AuthorManager(models.Manager):
+ def get_queryset(self):
+ qs = super().get_queryset()
+ return qs.filter(archived=False)
+
+
class Author(models.Model):
name = models.CharField(max_length=100)
+ archived = models.BooleanField(default=False)
+
+ objects = AuthorManager()
class Article(models.Model):
diff --git a/tests/validation/tests.py b/tests/validation/tests.py
index 46fe2f0c7b..5598b5ffe6 100644
--- a/tests/validation/tests.py
+++ b/tests/validation/tests.py
@@ -48,6 +48,13 @@ class BaseModelValidationTests(ValidationAssertions, TestCase):
mtv = ModelToValidate(number=10, name='Some Name', parent_id=parent.pk)
self.assertFailsValidation(mtv.full_clean, ['parent'])
+ def test_FK_validates_using_base_manager(self):
+ # Archived articles are not available through the default manager, only
+ # the base manager.
+ author = Author.objects.create(name="Randy", archived=True)
+ article = Article(title='My Article', author=author)
+ self.assertIsNone(article.full_clean())
+
def test_wrong_email_value_raises_error(self):
mtv = ModelToValidate(number=10, name='Some Name', email='not-an-email')
self.assertFailsValidation(mtv.full_clean, ['email'])