How to add a calculated field to a Django model

后端 未结 5 1398
情书的邮戳
情书的邮戳 2020-11-28 23:59

I have a simple Employee model that includes firstname, lastname and middlename fields.

On the admin side and li

5条回答
  •  自闭症患者
    2020-11-29 00:22

    In this case if you are only going to use the field for representation in admin site and such issues, you might better to consider overriding str() or unicode() method of the class as it is mentioned in django documentation here:

    class Employee(models.Model):
        # fields definitions
        def __str__(self):
            return self.lastname + ' ,' + self.firstname + ' ' + self.middlename
    

提交回复
热议问题