[Answered ]-Django Field Rename

2πŸ‘

βœ…

You could use verbose_name within the field parameter like this:

nameP = models.CharField(max_length=40, verbose_name='Name')
ageP  = models.CharField(max_length=40, verbose_name='Age')
...

You can also do this on Model classes as well with the Meta class. Say your Person class was actually named PPPerson, like this:

class PPPerson(models.Model):
    nameP = models.CharField(max_length=40, verbose_name='Name')
    ageP  = models.CharField(max_length=40, verbose_name='Age')
    class Meta:
        verbose_name = 'Person'
        verbose_name_plural = 'People'
πŸ‘€bnjmn

0πŸ‘

Use the `verbose_name’ parameter:

class Person(models.Model):
    nameP = models.CharField(max_length=40, verbose_name='Name')
    ageP  = models.CharField(max_length=40, verbose_name='Age')

    def __unicode__(self):
        return self.nameP
πŸ‘€jproffitt

0πŸ‘

You can rename field in model:

  1. Edit the field name in the model (but remember the old field name: you need it for step 3!)
  2. Create an empty migration

$ python manage.py makemigrations --empty myApp

  1. Edit the empty migration (it’s in the migrations folder in your app folder, and will be the most recent migration) by adding to the operations list

migrations.RenameField('MyModel', 'old_field_name', 'new_field_name')

  1. Apply the migration

$ python manage.py migrate myApp

Leave a comment