2👍
You could write a template tag, but I’d recommend making this a method on your model.
class Country(models.Model):
...
def get_population(self):
if self.population == int(self.population):
self.population = int(self.population)
return self.population
Then in your template, instead of
{{ obj.population }}
You would use this:
{{ obj.get_population }}
- Learning the Django framework
- How to embed matplotlib graph in Django webpage?
- How do I save data from a ModelForm to database in django?
Source:stackexchange.com