Django如何添加组模型字段

时间:2017-11-16 08:27:06

标签: django

我想添加一个描述归档组, 怎么做? 编辑源代码?

@python_2_unicode_compatible
class Group(models.Model):
    name = models.CharField(_('name'), max_length=80, unique=True)
    description = models.CharField(_('description'), max_length=180, 
        null=True, blank=True)  # add 
    permissions = models.ManyToManyField(
        Permission,
        verbose_name=_('permissions'),
        blank=True,
    )

    objects = GroupManager()

    class Meta:
        verbose_name = _('group')
        verbose_name_plural = _('groups')

    def __str__(self):
        return self.name

    def natural_key(self):
        return (self.name,)

并有其他方式?

1 个答案:

答案 0 :(得分:4)

尝试在models.py

中使用此功能
from django.contrib.auth.models import Group

Group.add_to_class('description', models.CharField(max_length=180,null=True, blank=True))