mirror of
https://github.com/django/django.git
synced 2025-10-10 07:19:11 +00:00
Refs #36580 -- Added coverage for excluding ForeignObject from constraint validation.
This commit is contained in:
parent
82b3b84a78
commit
308f674e6d
@ -1,5 +1,5 @@
|
|||||||
from .article import Article, ArticleIdea, ArticleTag, ArticleTranslation, NewsArticle
|
from .article import Article, ArticleIdea, ArticleTag, ArticleTranslation, NewsArticle
|
||||||
from .customers import Address, Contact, Customer
|
from .customers import Address, Contact, Customer, CustomerTab
|
||||||
from .empty_join import SlugPage
|
from .empty_join import SlugPage
|
||||||
from .person import Country, Friendship, Group, Membership, Person
|
from .person import Country, Friendship, Group, Membership, Person
|
||||||
|
|
||||||
@ -12,6 +12,7 @@ __all__ = [
|
|||||||
"Contact",
|
"Contact",
|
||||||
"Country",
|
"Country",
|
||||||
"Customer",
|
"Customer",
|
||||||
|
"CustomerTab",
|
||||||
"Friendship",
|
"Friendship",
|
||||||
"Group",
|
"Group",
|
||||||
"Membership",
|
"Membership",
|
||||||
|
@ -39,3 +39,22 @@ class Contact(models.Model):
|
|||||||
to_fields=["customer_id", "company"],
|
to_fields=["customer_id", "company"],
|
||||||
from_fields=["customer_code", "company_code"],
|
from_fields=["customer_code", "company_code"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerTab(models.Model):
|
||||||
|
customer_id = models.IntegerField()
|
||||||
|
customer = models.ForeignObject(
|
||||||
|
Customer,
|
||||||
|
from_fields=["customer_id"],
|
||||||
|
to_fields=["id"],
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
required_db_features = {"supports_table_check_constraints"}
|
||||||
|
constraints = [
|
||||||
|
models.CheckConstraint(
|
||||||
|
condition=models.Q(customer__lt=1000),
|
||||||
|
name="customer_id_limit",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
@ -15,6 +15,7 @@ from .models import (
|
|||||||
ArticleTag,
|
ArticleTag,
|
||||||
ArticleTranslation,
|
ArticleTranslation,
|
||||||
Country,
|
Country,
|
||||||
|
CustomerTab,
|
||||||
Friendship,
|
Friendship,
|
||||||
Group,
|
Group,
|
||||||
Membership,
|
Membership,
|
||||||
@ -767,3 +768,10 @@ class TestCachedPathInfo(TestCase):
|
|||||||
foreign_object_restored = pickle.loads(pickle.dumps(foreign_object))
|
foreign_object_restored = pickle.loads(pickle.dumps(foreign_object))
|
||||||
self.assertIn("path_infos", foreign_object_restored.__dict__)
|
self.assertIn("path_infos", foreign_object_restored.__dict__)
|
||||||
self.assertIn("reverse_path_infos", foreign_object_restored.__dict__)
|
self.assertIn("reverse_path_infos", foreign_object_restored.__dict__)
|
||||||
|
|
||||||
|
|
||||||
|
class ForeignObjectModelValidationTests(TestCase):
|
||||||
|
@skipUnlessDBFeature("supports_table_check_constraints")
|
||||||
|
def test_validate_constraints_excluding_foreign_object(self):
|
||||||
|
customer_tab = CustomerTab(customer_id=150)
|
||||||
|
customer_tab.validate_constraints(exclude={"customer"})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user