Django 1.9 InlineAdmin在自定义用户配置文件中显示重复字段

时间:2016-04-03 15:39:07

标签: django django-models django-admin

我是Django的新手。使用Django 1.9我创建了一个自定义用户模型,并通过对自定义用户模型进行子类化来扩展它。

models.py

 <blockquote>
 <p>
 Value to be changed on each button click
 </p>
 </blockquote>

以下是我的admin.py文件中的代码段

class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), max_length=255, unique=True, db_index=True)
    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_('Designates whether the user can log into this admin site.'))
    is_active = models.BooleanField(_('active'), default=USERS_AUTO_ACTIVATE,
                help_text=_('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.'))
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
    first_name = models.CharField(_('first name'), max_length=255, null=True, blank=True)
    last_name = models.CharField(_('last name'), max_length=255, null=True, blank=True)
    username = models.CharField(_('username'), max_length=100, unique=True, db_index=True, null=True, blank=True)
    mobile = models.CharField(_('mobile phone'), max_length=15, unique=True, null=True, blank=True)

    objects = UserInheritanceManager()
    base_objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = _('User')
        verbose_name_plural = _('Users')

class Profile(User, TimeStampedModel):
    gender_choices = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    gender = models.CharField(_('gender'), max_length=1, choices=gender_choices, null=True, blank=True)
    profile_image = models.ImageField(_('profile image'), upload_to=create_image_path, null=True, blank=True)

    class Meta:
        verbose_name = _('User Profile')
        verbose_name_plural = _('Users Profile')

当我尝试在django admin中编辑用户时,它会在UserProfile屏幕中显示用户模型字段,如密码,用户名,电子邮件等,即两次。我无法弄清楚为什么会这样。不是这些字段只应显示一次。任何帮助表示赞赏。

0 个答案:

没有答案