Hi,
I am trying to translate my model using django-modeltranslation and the SlugField is giving me a lot of trouble. I have successfully registered the fields for translation, as you can see in the db table description:
Table "public.news_news" Column | Type | Modifiers --------------+--------------------------+-------------------------------------------------------- id | integer | not null default nextval('news_news_id_seq'::regclass) title | character varying(255) | not null title_en | character varying(255) | title_nb | character varying(255) | slug | character varying(50) | not null slug_en | character varying(50) | slug_nb | character varying(50) |
But when I try to add a new News item, I am getting the following error:
Traceback: File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 372. return self.admin_site.admin_view(view)(*args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 202. return view(request, *args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 25. return bound_func(*args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 21. return func(self, *args2, **kwargs2) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/db/transaction.py" in inner 223. return func(*args, **kwargs) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view 1036. model_admin=self) File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/helpers.py" in __init__ 35. } for field_name, dependencies in prepopulated_fields.items()] File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/forms/forms.py" in __getitem__ 111. raise KeyError('Key %r not found in Form' % name) Exception Type: KeyError at /en/admin/news/news/add/ Exception Value: u"Key 'slug' not found in Form"
My admin.py :
from cmsplugin_news.admin import NewsAdmin as OldNewsAdmin class NewsAdmin(OldNewsAdmin, TranslationAdmin,): fields = ('title', 'slug') form = NewNewsForm
models.py:
class News(models.Model): title = models.CharField(_('Title'), max_length=255) slug = models.SlugField( _('Slug'), unique_for_date='pub_date', )
and forms.py:
class NewNewsForm(forms.ModelForm): class Meta: model = News fields = ('title', 'slug', )
As well, this is my translation.py where I declare the fields that should be translated by django-modeltranslation. I suppose anyhow that the error is not here, as the fields are already translated in db:
class NewsTranslationOptions(TranslationOptions): fields = ('title', 'slug', 'excerpt', 'content') translator.register(News, NewsTranslationOptions)
Any help please? I am really stuck! Thanks!
Roberto
No comments:
Post a Comment