2

我创建了一个自定义用户模型,如docs中所述。

模型.py

class Account(AbstractUser):
    middle_name = models.CharField(_('middle name'), max_length=30, blank=True)
    is_partner  = models.BooleanField(_('partner status'), default=False,
        help_text=_('Designates whether the user is partner or employee'))

表格.py

class AccountChangeForm(UserChangeForm):
    class Meta:
        model = Account

class AccountCreationForm(UserCreationForm):
    class Meta:
        model = Account

管理员.py

class AccountAdmin(UserAdmin):
    form = AccountChangeForm
    add_form = AccountCreationForm
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        (_('Personal info'), {'fields': ('first_name', 'middle_name', 'last_name', 'email')}),
        (_('Permissions'), {'fields': ('is_active', 'is_partner', 'is_staff', 'is_superuser',
                                       'groups', 'user_permissions')}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )

admin.site.register(Account, AccountAdmin)

一切正常,但现在用户和组在管理员的不同应用程序中: 单独的应用程序

是否可以将自定义用户模型和组放在一个应用程序中?

4

0 回答 0