invalid keyword argument for this function

288 views
Skip to first unread message

Carlos Joel Delgado Pizarro

unread,
Jul 18, 2014, 5:47:14 PM7/18/14
to django-mode...@googlegroups.com
Hello, I discovered django-modeltranslation and reading the docs I see it's what I need for my project, so I implemented it, but when I'm going to save a model I have, I got an error message:

'name_es' is an invalid keyword argument for this function

Here's my model:

class Event(models.Model):
    """
    Event model
    """
    name = models.CharField(
        max_length=140, verbose_name=_('Event name'))
    description = models.CharField(
        max_length=200, verbose_name=_('Description'), null=True, blank=True)
    organization = models.ForeignKey(Organization)


when I want to create an object, I got that error, example:

In[4]: from apps.event.models import Event
In[5]: e = Event.objects.create(name='evento uno', organization_id='1')

Traceback (most recent call last):
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-ebf1e3e61d3f>", line 1, in <module>
    e = Event.objects.create(name='evento uno', organization_id='1')
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/manager.py", line 157, in create
    return self.get_queryset().create(**kwargs)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/modeltranslation/manager.py", line 259, in create
    return super(MultilingualQuerySet, self).create(**kwargs)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/query.py", line 322, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/base.py", line 545, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/base.py", line 582, in save_base
    update_fields=update_fields, raw=raw, using=using)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/audit_log/models/managers.py", line 78, in post_save
    self.create_log_entry(instance, created and 'I' or 'U')
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/audit_log/models/managers.py", line 71, in create_log_entry
    manager.create(action_type = action_type, **attrs)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/manager.py", line 157, in create
    return self.get_queryset().create(**kwargs)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/query.py", line 320, in create
    obj = self.model(**kwargs)
  File "/home/anakin/virtenvs/cunuc/local/lib/python2.7/site-packages/django/db/models/base.py", line 417, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'name_es' is an invalid keyword argument for this function

I have 'modeltranslation' in my INSTALLED_APPS and this in my settings:
gettext = lambda s: s
LANGUAGES = (
    ('es', gettext('Spanish')),
    ('en', gettext('English')),
)
MODELTRANSLATION_DEFAULT_LANGUAGE = 'es'
MODELTRANSLATION_FALLBACK_LANGUAGES = ('es', 'en')

I have migrate my models, so I can see the fields in my DB, even I can see the data saved from the previous command and previous POST requests to the views where I save data, if I make a SELECT query on my Event table on PostgreSQL I can see the 'evento uno' created previously from running the last command and other data, so I don't know what's going wrong neither how to fix it.
I tried using .populate(True) and the same error is raised.

packages:
  Django==1.6.5
  django-modeltranslation==0.8b1
  South==0.1

Carlos Joel Delgado Pizarro

unread,
Jul 18, 2014, 6:03:47 PM7/18/14
to django-mode...@googlegroups.com

I got the guilty, I'm using django-audit-log[1] to have a history of the changes made on the model, so when I disable audit-log for my Event module, it worked fine without errors.
So django-audit-log and django-modeltranslation can't live together for now :/

[1] https://github.com/Atomidata/django-audit-log

Carlos Joel Delgado Pizarro

unread,
Jul 18, 2014, 6:31:21 PM7/18/14
to django-mode...@googlegroups.com
I replaced  django-audit-log with django-simple-audit[2] and everything works fine now.

[2] https://github.com/leandrosouza/django-simple-audit

Mikkel Mortensen

unread,
Aug 14, 2017, 10:55:38 AM8/14/17
to django-modeltranslation

For anyone else running into this problem, it's not necessary to replace `django-audit-log` with another, similar package.

I had the same issue, but after a while I figured out that you simply have to register the auto generated audit log models for translation as well as the regular models, as seen in this example: https://github.com/decibyte/django-auditlog-modeltranslation-testcase/compare/fix?expand=1#diff-f5e2c57158f98362114fabca111c67dfR7
Reply all
Reply to author
Forward
0 new messages