-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added available languages for models #678
base: master
Are you sure you want to change the base?
Conversation
Please, update documentation accordingly and add test for this feature. |
Co-authored-by: Serhii Tereshchenko <[email protected]>
This reverts commit 0735755.
…nto add_model_available_languages # Conflicts: # modeltranslation/translator.py
poetry.lock should not be touched, please revert. |
Take a look at And add similar for your feature.
|
…nto add_model_available_languages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, but you need to add tests before we can merge this.
Added tests. |
Resolved all errors that occurred during the tests and updated the documentation. |
modeltranslation/management/commands/update_translation_fields.py
Outdated
Show resolved
Hide resolved
def test_class_field(self): | ||
models.SpecificLanguageModelX.objects.create(title_x_de="foo", text="bar") | ||
models.SpecificLanguageModelX.objects.create(title_x_de="foo") | ||
|
||
y_foo = models.SpecificLanguageModelX.objects.filter(title_x_de="foo") | ||
assert 2 == y_foo.count() | ||
|
||
y_baz = models.SpecificLanguageModelX.objects.filter(title_x_de="baz") | ||
assert 0 == y_baz.count() | ||
|
||
def test_register_decorator(self): | ||
models.SpecificLanguageModelY.objects.create(title_y_de="foo", text="bar") | ||
models.SpecificLanguageModelY.objects.create(title_y_de="foo") | ||
|
||
y_foo = models.SpecificLanguageModelY.objects.filter(title_y_de="foo") | ||
assert 2 == y_foo.count() | ||
|
||
y_baz = models.SpecificLanguageModelY.objects.filter(title_y_de="baz") | ||
assert 0 == y_baz.count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two tests are essentially the same, different only model?
Replace it with single test and @pytest.mark.parametrize("model", ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, what this test supposed to check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, this test checked whether an error occurs when creating a database record if a model with the languages parameter is registered.
It is expected that if something goes wrong, the model will not be able to write data or retrieve it.
I will think about how to improve the tests to add more checks during the test.
Co-authored-by: Serhii Tereshchenko <[email protected]>
Co-authored-by: Serhii Tereshchenko <[email protected]>
…xt-adi/django-modeltranslation into add_model_available_languages
Added the ability to specify language codes during registration of translation fields. This allows for setting the translations needed for each model.
Progress