django-translated-fields | Django model translation without magic-inflicted pain | Translation library
kandi X-RAY | django-translated-fields Summary
kandi X-RAY | django-translated-fields Summary
Django model translation without magic-inflicted pain.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Fallback to the given field
- Convert name to attribute name
- Fallback to default
- Creates a getter for the given field name
- Creates a setter for the given field name
django-translated-fields Key Features
django-translated-fields Examples and Code Snippets
Community Discussions
Trending Discussions on django-translated-fields
QUESTION
I am trying to implement a multilingual Django website with help of django-translated-fields.
The project I am working on is based on cookiecutter-django and Docker.
The translation works fine for my model fields – except the slug filed. Actually translation of slug works as well but I am not able to take slug field for getting one single entry.
Excerpt of voting model:
...ANSWER
Answered 2019-May-12 at 18:43Not sure if this is the right way but with help of Django Documentation “How Django discovers language preference” I came to following solution.
Changing the voting view as follows:
QUESTION
Please take a look at this issue:
How do I use ModelForm with django-translated-fields?
Do you have any solution?
In short, I'm trying to convert Speedy Net from using django-modeltranslation
to django-translated-fields
. I defined the models and forms and everything works in English, but in another language (Hebrew) I have a problem that the form fields are defined in English instead of Hebrew (the current language). What did I do wrong and how do I define the form to work in the current language? (the fields defined by TranslatedField in the model should be visible only with the current language in the form SpeedyMatchProfileActivationForm).
I want to clarify that the desired definition is not as above. The desired definition is to use the current language in the form and not always English. Using English when the current language is not English is a bug.
You can see the code here:
The problem right now is with the class SpeedyMatchProfileActivationForm
(defined in forms.py). I think it is mainly because the class is defined before get_language()
returns anything. But when the class was defined with django-modeltranslation
(for example in branch staging), it worked.
By the way, one of the reasons I want to switch to django-translated-fields
is because it defines only 2 (the number of languages) fields in the database, and django-modeltranslation
defines 3 fields - one of them (the main field without any language) seems to me not necessary at all. Take a look at:
Remove original language field on migrations
class SpeedyMatchProfileActivationForm
is defined now (with django-translated-fields
, link):
ANSWER
Answered 2019-Mar-30 at 10:19I found a solution. It's not the optimal solution but it works. I added the fields in all languages to the form. The fields we don't need are already removed in the __init__
method.
QUESTION
I have a ModelForm
with Django 2.1, and I moved a few fields to another model. Calling make_migrations
causes an error because these fields don't exist in the current model. I added some of the fields to the form, but one of the fields is a TranslatedField
(from django-translated-fields) and therefore there are currently 2 fields, and in the future there might be more, depending on the number of languages. The name of the field is city, and currently I get an error message "Unknown field(s) (city_en, city_he) specified for SiteProfile
" (because I'm using 2 languages - "en" and "he") - but I want to create all the fields dynamically with a for loop over the languages we use in the project. Can I override (and is it a good programming method) the __new__
method or is there another way? I prefer not to hard-code the specific field names (city_en
and city_he
) because they may change in the future, depending on how many languages we use.
You can see my current commit (not working) on GitHub.
And the current code of this branch.
I would like to know what is the best programming method to define a dynamic list of fields (which are all identical, and only one of them will be used, the other are removed in the __init__
method) in a ModelForm where the fields are saved in another model (there are 2 models but only one form).
I still didn't commit the migrations because of this error when running make_migrations.
(I defined a command make_migrations
which only does makemigrations
)
The form (with my trying to override __new__
):
ANSWER
Answered 2019-Aug-15 at 15:06I don't know if this will help but I have a survey application where different users want different information on the background information form. I provide it via a json file. So within the form I have
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-translated-fields
You can use django-translated-fields like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page