Open CalBR opened 14 years ago
I don't think there is enough information here for me to analyze the problem. Can you post the stack trace of the "wrapped exception"?
Alternatively, the relevant pieces of code from your model/table/template might be helpful.
I don´t know what is the wrapped exception so, I´ll give you the other information but I think my files are pretty normal. The only not usual thing is that my foreign keys points to regular fields (using the to_field) and not id on other models.
from django.db import models
class Prodlist(models.Model): codigo = models.IntegerField('Codigo NCM', unique = True) descricao = models.CharField('Descricao', max_length = 200) unidade = models.CharField('Unidade', max_length = 2, blank = True)
def __unicode__(self):
return self.descricao
class Familia(models.Model): codigo = models.IntegerField('Familia#', unique = True) parent = models.ForeignKey('self', to_field = 'codigo', blank=True, null = True, related_name = 'child_set') divisao = models.CharField('Divisao', max_length = 10) marca = models.CharField('Marca', max_length = 10) descricao = models.CharField('Descricao', max_length = 50)
def __unicode__(self):
return self.descricao
class Produto(models.Model): codigo = models.IntegerField('Codigo', unique = True) descricao = models.CharField('Codigo', max_length = 35) unidade = models.CharField('Unidade', max_length = 2, choices = UNIDADES_VALIDAS) familia = models.ForeignKey('Familia', to_field = 'codigo') prodlist = models.ForeignKey('Prodlist', to_field = 'codigo')
def __unicode__(self):
return self.descricao
from django.shortcuts import render_to_response from prods.ibama.models import Familia, Produto, Prodlist import django_tables as tables
class ModeloTable(tables.ModelTable):
class Meta:
model = Produto
def list_mp(request): qs = Produto.objects.all() mats = ModeloTable(qs) return render_to_response('list_mp.html', {'table': mats})
{{ coluna }} | {% endfor %}
---|
{{ valor }} | {% endfor %}
TemplateSyntaxError at /ibama/list_mp/
Caught an exception while rendering: global name 'name' is not defined
Request Method: GET Request URL: http://localhost:8000/ibama/list_mp/ Exception Type: TemplateSyntaxError Exception Value:
Caught an exception while rendering: global name 'name' is not defined
Exception Location: E:\Django\Python26\lib\site-packages\django\template\debug.py in render_node, line 81 Python Executable: E:\Django\Python26\python.exe Python Version: 2.6.4 Python Path: ['E:\Django\prods', 'E:\Django\~dp0\Python26\Lib\site-packages', 'E:\Django\Python26\python26.zip', 'E:\Django\Python26\DLLs', 'E:\Django\Python26\lib', 'E:\Django\Python26\lib\plat-win', 'E:\Django\Python26\lib\lib-tk', 'E:\Django\Python26', 'E:\Django\Python26\lib\site-packages', 'E:\Django\Python26\lib\site-packages\PIL'] Server time: Sab, 21 Ago 2010 21:56:38 -0300
Try the latest head. I fixed a NameError there, presumably the one you're running into. The bad news is that this NameError occured while trying to display an exception, so you'll probably be seeing another error; one that should tell us more about what is wrong, though.
You are right. I´ve download and installed the latest version and executed my app using the same data and the error has changed, although pointing to the same problem: a foreign key which point to a "to_field" and not to the other model´s id.
The error now says: "Caught an exception while rendering: Could not resolve familia from familia".
"familia", as you may see above, is a foreign key in the model Produto. Everything else remains the same.
I found what was causing the error: there were some foreign keys with invalid values. I´ve corrected them and django-tables worked as expected.
It looks like it´s not managing correctly database errors when they happen in an associated model.
Hi
Everytime I try to use django-table on a model with foreignkey I receive an error message saying "global name 'name' is not defined". It does work as expected on the other models.
Environment:
Request Method: GET Request URL: http://localhost:8000/ibama/list_mp/ Django Version: 1.1.1 Python Version: 2.6.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'prods.ibama'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error: In template e:\django\prods\templates\list_mp.html, error at line 11 Caught an exception while rendering: global name 'name' is not defined 1 :
Traceback: File "E:\Django\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
Exception Type: TemplateSyntaxError at /ibama/list_mp/ Exception Value: Caught an exception while rendering: global name 'name' is not defined