The exception is thrown when someone tries to change a record in the admin interface that uses a OneToOneField? as a primary key.
Exception details:
KeyError at /admin/main/consultores/36/
'id_user'
Request Method: GET
Request URL: http://localhost:8000/admin/main/consultores/36/
Exception Type: KeyError
Exception Value: 'id_user'
Exception Location: /usr/lib/python2.3/site-packages/django/core/meta/fields.py in original_value, line 75
Template error
In template /usr/lib/python2.3/site-packages/django/contrib/admin/templates/admin/field_line.html, error at line 14
Caught an exception while rendering.
4 {% for bound_field in bound_fields %}
5 {% if bound_field.has_label_first %}
6 {% field_label bound_field %}
7 {% endif %}
8 {% field_widget bound_field %}
9 {% if not bound_field.has_label_first %}
10 {% field_label bound_field %}
11 {% endif %}
12 {% if change %}
13 {% if bound_field.field.primary_key %}
14 {{ bound_field.original_value }}
15 {% endif %}
16 {% if bound_field.raw_id_admin %}
17 {% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
18 {% endif %}
19 {% endif %}
20 {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %}
21 {% endfor %}
22 </div>
23
Traceback (innermost last)
Switch back to interactive view
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/django/core/template/__init__.py" in render_node
732. result = node.render(context)
File "/usr/lib/python2.3/site-packages/django/core/template/__init__.py" in render
778. output = self.filter_expression.resolve(context)
File "/usr/lib/python2.3/site-packages/django/core/template/__init__.py" in resolve
589. obj = resolve_variable(self.var, context)
File "/usr/lib/python2.3/site-packages/django/core/template/__init__.py" in resolve_variable
677. current = current()
File "/usr/lib/python2.3/site-packages/django/core/meta/fields.py" in original_value
76. return self.original.__dict__[self.field.column]
KeyError at /admin/main/consultores/36/
'id_user'
This is my model code:
class Utilizador(meta.Model):
id_user = meta.AutoField('ID', primary_key = True)
username = meta.CharField('Username', maxlength = 30, unique = True, null = True)
nome = meta.CharField('Nome', maxlength = 50, unique = True)
email = meta.EmailField('Email', unique = True, null = True)
telemovel = meta.CharField('Nr Telefone', maxlength = 9, unique = True, null = True)
class META:
admin = meta.Admin(list_display = ('id_user', 'username', 'nome', 'email', 'telemovel'))
db_table = 'users'
module_name = 'utilizadores'
verbose_name_plural = 'utilizadores'
def __repr__(self):
return self.nome
class Consultor(meta.Model):
user = meta.OneToOneField(Utilizador, verbose_name = 'Utilizador', db_column = 'id_user')
cod_consultor = meta.IntegerField('Codigo de consultor')
class META:
admin = meta.Admin(list_display = ('user', 'cod_consultor'))
db_table = 'consultores'
module_name = 'consultores'
verbose_name_plural = 'consultores'
def __repr__(self):
return self.get_user().nome