Can you change a field label in the Django Admin application?

前端 未结 5 945
甜味超标
甜味超标 2020-12-30 18:28

As the title suggests. I want to be able to change the label of a single field in the admin application. I\'m aware of the Form.field attribute, but how do I get my Model or

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 19:09

    As Javier suggested you can use verbose name in your fields in model.py. Example as below,

    class Employee(models.Model):
         name = models.CharField(max_length = 100)
         dob = models.DateField('Date Of Birth')
         doj = models.DateField(verbose_name='Date Of Joining')
         mobile=models.IntegerField(max_length = 12)
         email = models.EmailField(max_length=50)
         bill = models.BooleanField(db_index=True,default=False)
         proj = models.ForeignKey(Project, verbose_name='Project')
    

    Here the dob,doj and proj files will display its name in admin form as per the verbose_name mentioned to those fields.

提交回复
热议问题