如何重命名父母的字段名

时间:2019-11-12 07:34:48

标签: django django-models

class PermissionsMixin(models.Model):
    ...
    groups = models.ManyToManyField(
        Group,
        verbose_name=_('groups'),
        blank=True,
        help_text=_(
            'The groups this user belongs to. A user will get all permissions '
            'granted to each of their groups.'
        ),
        related_name="user_set",
        related_query_name="user",
    )
    ...

class AbstractUser(AbstractBaseUser, PermissionsMixin):
  ...
  ...

class MyUser(AbstractUser):

    //i want groups rename to roles

    class Meta:
        db_table = 'user'

我看到迁移具有RenameField,如何使用?代码非常清楚,为什么系统总是提示输入更多详细信息,白痴系统。

1 个答案:

答案 0 :(得分:0)

class User(AbstractUser):

    phone = models.CharField(blank=True, null=True, max_length=16)

    groups = AbstractUser._meta.get_field('groups')
    groups.db_column = 'roles'
    groups.name = 'roles'