Django Template and Bootstrap Tables
up vote
0
down vote
favorite
I have a django queryset that looks something like this
Group Label Name
A 1 Jack
A 2 Ryan
B 2 Alice
C 1 Sam
B 1 Mark
...
Basically, what I am attempting to do in my html, is create 6 small tables (2 rows of 3 tables). However, I want the first table to be Group A sorted by Label #, the second to be Group B sorted by Label #, etc.
I could bite the bullet and do 6 different django querysets, but this seems inefficient.
My initial thought was to have some counter in the django template to keep track of whether or not to start a new row. However, I am not sure if there is a way to filter & sort in the django template instead of the view.
Thanks for any help.
python html django bootstrap-4
add a comment |
up vote
0
down vote
favorite
I have a django queryset that looks something like this
Group Label Name
A 1 Jack
A 2 Ryan
B 2 Alice
C 1 Sam
B 1 Mark
...
Basically, what I am attempting to do in my html, is create 6 small tables (2 rows of 3 tables). However, I want the first table to be Group A sorted by Label #, the second to be Group B sorted by Label #, etc.
I could bite the bullet and do 6 different django querysets, but this seems inefficient.
My initial thought was to have some counter in the django template to keep track of whether or not to start a new row. However, I am not sure if there is a way to filter & sort in the django template instead of the view.
Thanks for any help.
python html django bootstrap-4
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a django queryset that looks something like this
Group Label Name
A 1 Jack
A 2 Ryan
B 2 Alice
C 1 Sam
B 1 Mark
...
Basically, what I am attempting to do in my html, is create 6 small tables (2 rows of 3 tables). However, I want the first table to be Group A sorted by Label #, the second to be Group B sorted by Label #, etc.
I could bite the bullet and do 6 different django querysets, but this seems inefficient.
My initial thought was to have some counter in the django template to keep track of whether or not to start a new row. However, I am not sure if there is a way to filter & sort in the django template instead of the view.
Thanks for any help.
python html django bootstrap-4
I have a django queryset that looks something like this
Group Label Name
A 1 Jack
A 2 Ryan
B 2 Alice
C 1 Sam
B 1 Mark
...
Basically, what I am attempting to do in my html, is create 6 small tables (2 rows of 3 tables). However, I want the first table to be Group A sorted by Label #, the second to be Group B sorted by Label #, etc.
I could bite the bullet and do 6 different django querysets, but this seems inefficient.
My initial thought was to have some counter in the django template to keep track of whether or not to start a new row. However, I am not sure if there is a way to filter & sort in the django template instead of the view.
Thanks for any help.
python html django bootstrap-4
python html django bootstrap-4
asked Nov 9 at 16:48
a.powell
4181617
4181617
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54
add a comment |
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Here's what I would do:
- Order the queryset the way you want (sorted by group, then by label) by using the order_by operation.
- In your template, use the ifchanged conditional to test to see when you have a different group. In that case, you output the table tags as necessary.
Example of item 2 above:
% for object in queryset %
% ifchanged obj.group %
<table>
% endifchanged %
<tr>
<td> obj.label </td>
<td> obj.name </td>
</tr>
% ifchanged obj.group %
</table>
% endifchanged %
% endfor %
Thank you! This works, except the lastifchanged
doesn't work. I removed that section and added a</table>
BEFORE<table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap
– a.powell
Nov 9 at 17:25
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Here's what I would do:
- Order the queryset the way you want (sorted by group, then by label) by using the order_by operation.
- In your template, use the ifchanged conditional to test to see when you have a different group. In that case, you output the table tags as necessary.
Example of item 2 above:
% for object in queryset %
% ifchanged obj.group %
<table>
% endifchanged %
<tr>
<td> obj.label </td>
<td> obj.name </td>
</tr>
% ifchanged obj.group %
</table>
% endifchanged %
% endfor %
Thank you! This works, except the lastifchanged
doesn't work. I removed that section and added a</table>
BEFORE<table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap
– a.powell
Nov 9 at 17:25
add a comment |
up vote
0
down vote
Here's what I would do:
- Order the queryset the way you want (sorted by group, then by label) by using the order_by operation.
- In your template, use the ifchanged conditional to test to see when you have a different group. In that case, you output the table tags as necessary.
Example of item 2 above:
% for object in queryset %
% ifchanged obj.group %
<table>
% endifchanged %
<tr>
<td> obj.label </td>
<td> obj.name </td>
</tr>
% ifchanged obj.group %
</table>
% endifchanged %
% endfor %
Thank you! This works, except the lastifchanged
doesn't work. I removed that section and added a</table>
BEFORE<table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap
– a.powell
Nov 9 at 17:25
add a comment |
up vote
0
down vote
up vote
0
down vote
Here's what I would do:
- Order the queryset the way you want (sorted by group, then by label) by using the order_by operation.
- In your template, use the ifchanged conditional to test to see when you have a different group. In that case, you output the table tags as necessary.
Example of item 2 above:
% for object in queryset %
% ifchanged obj.group %
<table>
% endifchanged %
<tr>
<td> obj.label </td>
<td> obj.name </td>
</tr>
% ifchanged obj.group %
</table>
% endifchanged %
% endfor %
Here's what I would do:
- Order the queryset the way you want (sorted by group, then by label) by using the order_by operation.
- In your template, use the ifchanged conditional to test to see when you have a different group. In that case, you output the table tags as necessary.
Example of item 2 above:
% for object in queryset %
% ifchanged obj.group %
<table>
% endifchanged %
<tr>
<td> obj.label </td>
<td> obj.name </td>
</tr>
% ifchanged obj.group %
</table>
% endifchanged %
% endfor %
answered Nov 9 at 16:57
Jonah Bishop
7,72832957
7,72832957
Thank you! This works, except the lastifchanged
doesn't work. I removed that section and added a</table>
BEFORE<table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap
– a.powell
Nov 9 at 17:25
add a comment |
Thank you! This works, except the lastifchanged
doesn't work. I removed that section and added a</table>
BEFORE<table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap
– a.powell
Nov 9 at 17:25
Thank you! This works, except the last
ifchanged
doesn't work. I removed that section and added a </table>
BEFORE <table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap– a.powell
Nov 9 at 17:25
Thank you! This works, except the last
ifchanged
doesn't work. I removed that section and added a </table>
BEFORE <table>
to close the previous table if group has changed. I still have to figure out how to make the columns and rows with bootstrap– a.powell
Nov 9 at 17:25
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230016%2fdjango-template-and-bootstrap-tables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Where is the code you have tried for that?
– mlegg
Nov 9 at 16:54