Ticket #136 (closed defect: wontfix)
south doesn't like django-multilingual
| Reported by: | anonymous | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | commands | Version: | 0.6-pre |
| Keywords: | Cc: | patrick.lauber@… |
Description
<<<
Traceback (most recent call last):
File "../mobimotower.ch/py_src/mobimo/manage.py", line 11, in <module>
execute_manager(settings)
File "/Users/patricklauber/Documents/workspace/django/django/core/management/init.py", line 340, in execute_manager
utility.execute()
File "/Users/patricklauber/Documents/workspace/django/django/core/management/init.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/patricklauber/Documents/workspace/django/django/core/management/base.py", line 192, in run_from_argv
self.execute(*args, options.dict)
File "/Users/patricklauber/Documents/workspace/django/django/core/management/base.py", line 219, in execute
output = self.handle(*args, options)
File "/Users/patricklauber/Documents/workspace/dlib/python/py2/south/management/commands/startmigration.py", line 544, in handle
all_models[model_key(model)] = prep_for_freeze(model, last_models)
File "/Users/patricklauber/Documents/workspace/dlib/python/py2/south/management/commands/startmigration.py", line 586, in prep_for_freeze
fields = modelsparser.get_model_fields(model, m2m=True)
File "/Users/patricklauber/Documents/workspace/dlib/python/py2/south/modelsparser.py", line 311, in get_model_fields
raise ValueError?("Cannot find source for model '%s'." % model)
ValueError?: Cannot find source for model '<class 'links.models.LinkTranslation?'>'.
If a field is makred as translateable mit django-multilingual south gives the above error
Attachments
Change History
comment:2 Changed 4 years ago by andrew
- Status changed from new to closed
- Version set to subversion
- Resolution set to wontfix
Yes, the problem here is that multilingual is one of those apps that creates models on-the-fly; I always knew these wouldn't work with South, and that's a design choice at the moment. If and when introspecting models becomes feasible, this might change, but for now, this is a WONTFIX.
comment:3 Changed 4 years ago by andrew
(from mailing list)
Simple workaround
define your Translation outside of the model:
class BlogTranslation(multilingual.Translation):
title = models.CharField(max_length=255)
class Blog(models.Model):
Translation = BlogTranslation
owner = models.ForeignKey(User, related_name="blogs")
Now the Translation model will be picked up by South.
You'll still need to add definitions to two fields in the migration:
('language_id', models.PositiveIntegerField()),
('master', models.ForeignKey(orm.Blog, related_name="translations")),
and also in the models section:
'language_id': ('models.PositiveIntegerField', [], {}),
'master': ('models.ForeignKey', ["orm['blog.Blog']"], {'related_name':
'"translations"'}),
Changed 4 years ago by neeleshs@…
- Attachment modelsparser.py added
modelparsers.py. See get_model_tree(..)
comment:4 Changed 4 years ago by neeleshs@…
In our project,we ran in to the same issue. Most of our models were multilingual and we wanted to avoid manually editing the generated migration files. So we modified modelparser.py, get_model_tree(...) to "generate" the source for on-the-fly models. Its worked well so far.
If you find that there is any value in this approach, please let me know, I'll attach a formal patch file.(Right now, there is a bit of multilingual specific hard-coding)
comment:5 Changed 4 years ago by andrew
South now uses introspection, not parsing, to generate source, and so works better with dynamically-created code. django-multilingual can probably be supported in a similar way to django-modeltranslation, for which I have a patch at http://code.google.com/p/django-modeltranslation/issues/detail?id=11
comment:6 Changed 4 years ago by Peppe bergqvist
I have made a patch fro django-multilingual that solves this, take a look at http://code.google.com/p/django-multilingual/issues/detail?id=111 for more info.

Just as a side note: I don't think django-multilingual is a good thing to use, it's too magical. Therefore I don't think South should really handle django-multilingual.
For a workaround, see how multilingualism is done in Satchmo (it's an e-commerce solution written in Django).