mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-05-18 09:31:10 +00:00
Fix deferred classes signal connection (close #379).
This commit is contained in:
parent
9e10e49543
commit
a7b5102c43
2 changed files with 13 additions and 1 deletions
|
|
@ -2958,6 +2958,13 @@ class TestManager(ModeltranslationTestBase):
|
|||
self.assertIn('text_en', dir(item1.__class__))
|
||||
self.assertIn('text_de', dir(item1.__class__))
|
||||
|
||||
def test_deferred_rule2(self):
|
||||
models.TestModel.objects.create(title_de='title_de', title_en='title_en')
|
||||
o = models.TestModel.objects.only('title')[0]
|
||||
self.assertEqual(o.title, "title_en")
|
||||
o.title = "bla"
|
||||
self.assertEqual(o.title, "bla")
|
||||
|
||||
def test_translation_fields_appending(self):
|
||||
from modeltranslation.manager import append_lookup_keys, append_lookup_key
|
||||
self.assertEqual(set(['untrans']), append_lookup_key(models.ForeignKeyModel, 'untrans'))
|
||||
|
|
|
|||
|
|
@ -490,7 +490,12 @@ class Translator(object):
|
|||
patch_constructor(model)
|
||||
|
||||
# Connect signal for model
|
||||
post_init.connect(delete_mt_init, sender=model)
|
||||
if NEW_DEFERRED_API:
|
||||
post_init.connect(delete_mt_init, sender=model)
|
||||
else:
|
||||
# deferred models have their own classes and the `sender` does not match.
|
||||
# Connect signal for all models.
|
||||
post_init.connect(delete_mt_init, dispatch_uid="modeltranslation")
|
||||
|
||||
# Patch clean_fields to verify form field clearing
|
||||
patch_clean_fields(model)
|
||||
|
|
|
|||
Loading…
Reference in a new issue