I’m entering in values in the admin section currently. As I get to it it will be in a form from a webpage. That doesn’t matter though, just for context. I will leave the calc function in the model. So I’ll use the last example.
from django.contrib import admin
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=50)
birthday = models.DateField()
@admin.display(description='Birth decade')
def decade_born_in(self):
return '%d’s' % (self.birthday.year // 10 * 10)
class PersonAdmin(admin.ModelAdmin):
list_display = ('name', 'decade_born_in')
If that’s good I’ll ask another question. So far so good?