|
8 | 8 | from django.utils.translation import override
|
9 | 9 |
|
10 | 10 | from modeltrans.fields import TranslationField
|
11 |
| -from tests.app.models import Blog, NullableTextModel, TextModel |
| 11 | +from tests.app.models import Article, Blog, ChildArticle, NullableTextModel, TextModel |
12 | 12 |
|
13 | 13 | from .utils import CreateTestModel
|
14 | 14 |
|
@@ -268,6 +268,33 @@ def test_defer_i18n(self):
|
268 | 268 | blog.title_i18n
|
269 | 269 |
|
270 | 270 |
|
| 271 | +class TranslatedFieldInheritanceTest(TestCase): |
| 272 | + def test_child_model_i18n_fields(self): |
| 273 | + self.assertFalse(hasattr(Article, "child_title_nl")) |
| 274 | + self.assertTrue(hasattr(ChildArticle, "child_title_nl")) |
| 275 | + |
| 276 | + def test_child_model_required_languages(self): |
| 277 | + self.assertTrue(Article._meta.get_field("title_nl").blank) |
| 278 | + self.assertFalse(ChildArticle._meta.get_field("title_nl").blank) |
| 279 | + |
| 280 | + def test_diff_i18n_parent_child_models_instances(self): |
| 281 | + """ |
| 282 | + Test different behavior of Article and ChildArticle instances |
| 283 | + """ |
| 284 | + article = Article(title="Title") |
| 285 | + article.full_clean() |
| 286 | + article.save() |
| 287 | + child_article = ChildArticle(title="Title", child_title="Child title") |
| 288 | + with self.assertRaises(ValidationError): |
| 289 | + child_article.full_clean() |
| 290 | + child_article.title_nl = "Title NL" |
| 291 | + child_article.child_title_nl = "Child title NL" |
| 292 | + child_article.full_clean() |
| 293 | + child_article.save() |
| 294 | + self.assertFalse("child_title_nl" in article.i18n) |
| 295 | + self.assertTrue("child_title_nl" in child_article.i18n) |
| 296 | + |
| 297 | + |
271 | 298 | class RefreshFromDbTest(TestCase):
|
272 | 299 | def test_refresh_from_db(self):
|
273 | 300 | b = Blog.objects.create(title="Falcon", i18n={"title_nl": "Valk", "title_de": "Falk"})
|
|
0 commit comments