Subtracting two fields in a template

后端 未结 1 1550
心在旅途
心在旅途 2021-01-07 08:42

I\'m trying to loop through objects from my database in the template and one of the things I want to display is the difference between two of the fields in the table. Is th

1条回答
  •  误落风尘
    2021-01-07 09:05

    Django templates are designed not to do computation. You should adjust your games list in the view, then display it in the template:

    # views.py
    for game in games:
        game.chars_diff = game.num_Players - game.accepted_Characters
    
    
    # template.html
    

    {{ game.chars_diff }}

    0 讨论(0)
提交回复
热议问题