where should i code? at views.py or at the html file?
In the view, definitely. A template is only meant for rendering logic, so presenting the data you already retrieved in a nice way. The view is responsible to retrieve the data or update data.