Comments (5)
Well, the models can handle it for sure. I'm just not sure if that can be done in the admin but it's worth a try! Would be really cool to have! :-)
I've wanted this to work in standard Django forms for some time now, because the parler-oscar integration does suffer from exposing just one language in the form. Having a form class that can generate fields for all languages would be a first good start to implement this!
from django-parler.
+1
Having only one language at once with the form class can cause problems. It would be nice if the form class automatically showed all languages. "Description (EN), Description (FR), etc.".
I find myself programming manual forms everytime there's a multilingual component.
from django-parler.
Here is how I do my forms it in the meantime.
This is an example where "name" and "description" are multilingual fields.
from parler.forms import TranslatableModelForm, TranslatedField
from django.utils.translation import gettext_lazy as _
from django.conf import settings
class MyForm(TranslatableModelForm):
#add all multilingual fields to the form
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
for lang_code, lang_name in settings.LANGUAGES:
#I have no clue why this doesn't work without the try/except.
try:
self.instance.set_current_language(lang_code)
self.fields["name_"+lang_code] = forms.CharField(label=_("Name ")+" ("+lang_code+")", max_length=100, required=True, initial=self.instance.name)
except:
self.instance.set_current_language(lang_code)
#Save all multilingual fields
def save(self, commit=True):
instance = super(MyForm, self).save(commit=False)
instance.save()
for lang_code, lang_name in settings.LANGUAGES:
instance.set_current_language(lang_code)
instance.name = self.cleaned_data['name_'+lang_code]
instance.save()
return instance
class Meta:
model = MyModel
fields = '__all__'
exclude = ("name", "description",) #exclude multilingual fields because they are dealt with above
from django-parler.
@svezina what is the exception that you are catching? Probably by knowing what is the exception someone can understand why happens.
from django-parler.
I think the issue here is getting values from the translated instance for the initial data. That will fail upon creation and if a field is not set yet in the model. At least that is what I have with django 1.8 and parler 1.6.4
mymodel does not have a translation for the current language!
MyModel ID #5, language=de (tried fallbacks en)
Attempted to read attribute title.
from django-parler.
Related Issues (20)
- Deleting a record - ManyToMany Field StackOverflow error
- Migrate from django-hvad
- django-hvad migration: How to modify old migrations?
- django-treebeard
- Clearing FileField don't work
- dumpdata & loaddata manage.py command with django parler HOT 1
- "wrong number of arguments for 'del' command" when deleting TranslatableModel using Redis cache
- Django Parler shows translated object one time per translation on the admin list HOT 6
- Store translated model to/from more than one database fails
- get_or_create not working HOT 2
- (Bug) `bulk_create` on TranslatableModel HOT 1
- (Bug) Redis cache "wrong number of arguments for 'del' command"
- Async and parler
- Is the package still maintained? HOT 2
- django-parler does not honor validators attribute -- validation possible at all?
- how to translate a form with parler_tags.
- django-parler with unique field raise IntegrityError
- how do I translate a easy_thumbnails.fields.ThumbnailerImageField
- Tags are not being saved when using django-taggit with django-parler.
- Creation of the parent, although max length has been exceeded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-parler.