2017-11-27 2 views
0

私はdjangoテンプレートでテーブルを使用しています。私は文脈でオブジェクトの2つの配列をテンプレートに渡しました。オブジェクトの2つの配列をループしているとき、if条件が失敗したときに問題が発生しています。条件が満たされない場合、それは後のtdの値を前の値に置きます。条件が満たされていない場合、空のtdを提供するためにelseを適用しようとしました。しかし、else条件のため、すべての条件で最初の4つのブロックをスキップします。djangoテンプレートでループを作成してテーブルデータにイヤリングを作成する

if条件が満たされていない場合は、最初にtd(テーブルデータ)に空白を入れたいだけです。

<table id="searchFilterNewAdmin" class="table table-striped table-bordered table-hover" > 
    <thead> 
     <tr role="row"> 
      <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">Admin Name</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending">Tablet No</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending">Region</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending">Car Make</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">Total Time(s)</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">Last Opened</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">No.of Clicks</th> 
      <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">Average Time(s)</th> 
     </tr> 
    </thead> 
    <tbody> 
     {% for all in admin_time_stats %} 
      <tr> 
       {% for every in all_tabletadmins %} 
        {% if all.tablet_number == every.tablet_number %} 
         <td>{{ every.first_name }}</td> 
         <td>{{ every.tablet_number }}</td> 
         <td>{{ every.region }}</td> 
         <td>{{ every.car_year}}</td> 
        {% else %} 
         <td></td> 
         <td></td> 
         <td></td> 
         <td></td> 
        {% endif %} 
       {% endfor %} 
       <td>{{ all.total_time }}</td> 
       <td>{{ all.start_time }}</td> 
       <td>{{ all.no_of_clicks }}</td> 
       <td>{% widthratio all.total_time all.no_of_clicks 1 %}</td> 
      </tr> 
     {% endfor %} 
    </tbody> 
</table> 

admin_time_stats = [{'no_of_clicks': 15, 'tablet_number': 'tablet9', 'start_time': datetime.datetime(2017, 11, 24, 13, 57, 8, 64000, tzinfo=), 'total_time': 480}{'no_of_clicks': 1, 'tablet_number': 'tablet10', 'start_time': datetime.datetime(2017, 11, 8, 17, 18, 27, 389000, tzinfo=), 'total_time': 32}] 


all_tabletadmins = [{'tablet_number': 'tablet9', 'region': 'usa', 'car_year': '1991', 'admin_name': 'sam' }] 
+0

{% endfor %}を追加したものをお使いの二つのリスト、 'admin_time_stats'と' all_tabletadmins'見てください好きですか? – wholevinski

+0

確かに質問を編集して追加しました –

+0

elseブロックの '​​'を削除してみるといいですか?そうでなければ本質的にノーオペレーションですか? – wholevinski

答えて

0

あなたはの例を投稿することができます</tr>タグ

関連する問題