during appending the result (appending foreign key ) causes key error
models.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()
views.py
def relation(request)
"""
some stuff
"""
query = "query set makes object of table 1"
result['content'].append([query['ref__address'])
the error is
Keyerror at /url
ref__address
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'),
)
Your problem seems to be that none of your python was valid.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.