0

在附加结果期间(附加外键)导致键错误

模型.py

class table1
    id = models.IntegerField( primary key=TRUE)
    ref = models.ForeignKey('table2')

class table2
    name = models.CharField()
    id = models.IntegerField(primaryKey= True)
    address = models.CharField()

视图.py

def relation(request)
"""
    some stuff
"""
    query = "query set makes object of table 1"

    result['content'].append([query['ref__address'])

错误是

Keyerror at /url
ref__address
4

1 回答 1

1
def relation(request, pk):
    item = get_object_or_404(Table1, pk=pk)
    context= {'content': item}
    return render(request, 'table1/relation.html', context)

urlpatterns = patterns('',
    url(r'^table1/(?P<pk>\d+)/$', relation, name='relation'),
)

你的问题似乎是你的 python 都不是有效的。

于 2013-08-26T10:43:09.630 回答