display time_frame and is_primary in similar features list

This commit is contained in:
Sanj 2011-08-31 02:31:51 +05:30
parent 777f41a16f
commit 279cb18b91
3 changed files with 30 additions and 1 deletions

View File

@ -53,13 +53,22 @@ def search_related_json(request):
feature = get_object_or_404(Feature, pk=id)
similar_features = feature.similar_features()
d = []
for s in similar_features:
f = Feature.objects.get(pk=s.id) # This seems inefficient - better to get something like time_frame_id in models method? TODO
if f.time_frame is not None:
time_frame = f.time_frame.description
else:
time_frame = ''
d.append({
'id': s.id,
'feature_type': FeatureType.objects.get(pk=s.feature_type_id).name,
'preferred_name': s.preferred_name,
'similarity': s.similarity,
'distance': s.distance
'distance': s.distance,
'time_frame': time_frame,
'is_primary': s.is_primary
})
return render_to_json_response(d)

View File

@ -16,5 +16,14 @@ function getRow(d) {
$('<td />').text(d.feature_type).appendTo($tr);
$('<td />').text(d.similarity).appendTo($tr);
$('<td />').text(d.distance).appendTo($tr);
$('<td />').text(d.time_frame).appendTo($tr);
var $primary_td = $('<td />').appendTo($tr);
var $checkbox = $('<input />').attr("type", "checkbox").attr("disabled", "disabled").appendTo($primary_td);
if (d.is_primary) {
$checkbox.attr("checked", "checked");
} else {
$.noop();
}
return $tr;
}

View File

@ -32,6 +32,17 @@
<th>
Distance
</th>
<th>
Time Frame
</th>
<th>
Is Primary?
</th>
<!--
<th>
Relation
</th>
-->
</tr>
</thead>
<tbody>