나는 내 응용 프로그램에서이보기가 있습니다값의 사전을 기반으로 빈 셀이있는 테이블을 쓰기
이def context_detail(request, context_id):
c = get_object_or_404(Context, pk=context_id)
scs = SherdCount.objects.filter(assemblage__context=c).exclude(count__isnull=True)
total = sum(sc.count for sc in scs)
table = []
forms = []
for a in c.assemblage_set.all():
for sc in a.sherdcount_set.all():
forms.append(sc.typename)
forms_set = set(forms)
for a in c.assemblage_set.all():
diko = {}
diko['assemblage'] = a
for f in forms_set:
for sc in a.sherdcount_set.all():
if f == sc.typename:
diko[f] = sc.count
else:
diko[f] = 0
table.append(diko)
return render_to_response('tesi/context_detail.html',
{'context': c, 'total': total, 'sherdcounts': scs, 'table': table, 'forms': forms_set},
context_instance=RequestContext(request))
루프에 대한 두 가지의 목적은 SherdCount의 값을 보유하고 사전의 목록을 만드는 그 것을 .count SherdCount.typename 외래 키 참조 (현재 코드가 엉망인 경우에도 가능).
[{<Type: Hayes 61B>: 0, <Type: Hayes 99A-B>: 0, <Type: Hayes 105>: 0, <Type: Hayes 104A>: 0, <Type: Hayes 104B>: 0, <Type: Hayes 103>: 0, <Type: Hayes 91>: 0, <Type: Hayes 91A>: 0, <Type: Hayes 91B>: 0, <Type: Hayes 91C>: 0, <Type: Hayes 91D>: 0, <Type: Hayes 85B>: 0, <Type: Hayes 82A>: 0, <Type: Hayes 76>: 0, <Type: Hayes 73>: 0, <Type: Hayes 72>: 0, <Type: Hayes 70>: 0, <Type: Hayes 68>: 0, <Type: Hayes 67>: 0, <Type: Hayes 66>: 0, <Type: Hayes 62A>: 0, <Type: Hayes 80B>: 0, <Type: Hayes 59>: 0, <Type: Hayes 61A>: 0, <Type: Hayes 91A-B>: 0, <Type: Hayes 58>: 0, <Type: Hayes 50>: 0, <Type: Hayes 53>: 0, <Type: Hayes 71>: 0, <Type: Hayes 60>: 0, <Type: Hayes 80A>: 0, <Type: Hayes Style A2-3>: 0, <Type: Hayes Style B>: 0, <Type: Hayes Style E1>: 1, 'assemblage': <Assemblage: Brescia, Santa Giulia : non periodizzato>}, {<Type: Hayes 61B>: 0, <Type: Hayes 99A-B>: 0, <Type: Hayes 105>: 0, <Type: Hayes 104A>: 0, <Type: Hayes 104B>: 0, <Type: Hayes 103>: 0, <Type: Hayes 91>: 0, <Type: Hayes 91A>: 0, <Type: Hayes 91B>: 0, <Type: Hayes 91C>: 0, <Type: Hayes 91D>: 0, <Type: Hayes 85B>: 0, <Type: Hayes 82A>: 0, <Type: Hayes 76>: 0, <Type: Hayes 73>: 0, <Type: Hayes 72>: 0, <Type: Hayes 70>: 0, <Type: Hayes 68>: 0, <Type: Hayes 67>: 0, <Type: Hayes 66>: 0, <Type: Hayes 62A>: 0, <Type: Hayes 80B>: 0, <Type: Hayes 59>: 0, <Type: Hayes 61A>: 0, <Type: Hayes 91A-B>: 0, <Type: Hayes 58>: 0, <Type: Hayes 50>: 0, <Type: Hayes 53>: 0, <Type: Hayes 71>: 0, <Type: Hayes 60>: 0, <Type: Hayes 80A>: 0, <Type: Hayes Style A2-3>: 0, <Type: Hayes Style B>: 3, <Type: Hayes Style E1>: 0, 'assemblage': <Assemblage: Brescia, Santa Giulia : Periodo IIIA>},
그러나 많은 0 값은 분명히 잘못 :
은 "테이블"목록
는 다음과 같이 포함되어야합니다. 비록 일부 0이있을지라도 (예를 들어 내가 말했던 빈 셀)그런 목록을 작성한 후에는 모든 셀 (예 : 1 행당 1 행)의 테이블을 어떻게 만들 수 있습니까? 셀당 SherdCount와 함께 컨텍스트 당 유형 및 1 열)?
Steko
결과 테이블 구조의 샘플을 보여주는 것이 도움이됩니다. –
물론입니다. http://www.linux.it/~steko/static/tesi/contexts/9/index.html 다음은 "Forme"제목 아래에있는 기본 데이터의 예입니다. http://paste.pocoo.org/show/108661/과 같은 것을 원합니다. (순진하지만 아이디어를줍니다.) – steko
'table' 변수의 값 샘플로 질문을 업데이트 할 수 있습니까? –