Week #02 - 2023

Week #02 - 2023


2 min read

If you need to create a table where you can select multiple rows using the combination of the Shift key and a mouse click, here is how you do it using django-tables2 and AlpineJS. Note that this table has a checkbox column. First, you need to define an event handler for each checkbox. Just add attrs={"td__input": {"@click": "checkRange"}} to your CheckBoxColumn definition.

class TheTable(tables.Table):  
    selection = tables.CheckBoxColumn(accessor="pk", orderable=False,   
                                        "td__input": {  
                                            "@click": "checkRange"  

Second, in your template, implement the event handler.

    // Set the checkbox to be checked from the start to end
    // when a user presses the shift key.
    function checkRange(event) {  
        let checkboxes = document.getElementsByName('selection');  
        let inBetween =  false;  
        if( event.shiftKey && event.target.checked ) {  
            checkboxes.forEach( checkbox => {  
                if( checkbox === event.target || checkbox === last_checked ) {  
                    inBetween = !inBetween;  
                if( inBetween ) {  
                    checkbox.checked = true;  
        last_checked = event.target;  

I am about 17% into Strategy: A History book. So far, I have learned a lot. Several ideas or concepts that I have learned:

  • Strategy is a natural consequence of scarce vital resources and the struggle for survival.

  • Strength vs. Wisdom. Success doesn't rely solely on force and violence. Success could come as much from being smart as being strong.

  • Clausewitz has this concept of "friction": Countless minor incidents that lower the performance so that you always fall short of the intended goal. This is important because it highlights war's inherent uncertainty and unpredictability and the importance of flexibility and adaptability in military strategy.

  • However, while you should be flexible, Clausewitz also thinks you should make a clear plan. Because while most things are unpredictable, not everything is a mystery. But keep the plan simple, especially against a capable opponent.

  • The importance of execution vs. planning. According to the book, Napoleon is great not because his strategy is original but on the boldness of his execution.