Bootstrap table to company list

This commit is contained in:
Oliver 2018-05-02 23:17:24 +10:00
parent 1899d8f3e9
commit be0797c6e6
3 changed files with 40 additions and 21 deletions

View File

@ -5,6 +5,8 @@ from .models import Company
class CompanySerializer(serializers.HyperlinkedModelSerializer):
url = serializers.CharField(source='get_absolute_url', read_only=True)
class Meta:
model = Company
fields = '__all__'

View File

@ -6,26 +6,7 @@
<h3>Companies</h3>
<table class='table table-striped' id='company-table' data-sorting='true' data-filtering='true'>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for company in companies %}
<tr>
<td>
<a href="{% url 'company-detail' company.id %}">
{{ company.name }}
</a>
</td>
<td>{{ company.description }}</td>
</tr>
{% endfor %}
</tbody>
<table class='table table-striped' id='company-table'>
</table>
<div class='container-fluid'>
@ -48,4 +29,40 @@
follow: true
});
});
$("#company-table").bootstrapTable({
sortable: true,
search: true,
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'name',
title: 'Company',
sortable: true,
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
field: 'description',
title: 'Description',
},
{
field: 'website',
title: 'Website',
formatter: function(value, row, index, field) {
if (value) {
return renderLink(value, value);
}
return '';
}
}
],
url: "{% url 'api-company-list' %}"
});
{% endblock %}

View File

@ -59,5 +59,5 @@
sortable: true,
}
],
url: 'http://127.0.0.1:8000/api/part/',
url: "{% url 'api-part-list' %}",
});