当前位置: 首页 > 工具软件 > Mezzanine > 使用案例 >

Mezzanine user 扩展

颜黎昕
2023-12-01

  1. 先按照django 官网的配置  来扩展user
  2. 比如myapp modles
  3. from django.db import models
    from django.contrib.auth.models import User
    from django.contrib import admin
    from django.db.models.signals import post_save
    class UserProfile(models.Model):
        # This field is required.
        user = models.OneToOneField(User)


        # Other fields here
        accepted_eula = models.BooleanField()
        favorite_animal = models.CharField(max_length=20, default="Dragons.")
        def create_user_profile(sender, instance, created, **kwargs):
            if created:
                UserProfile.objects.create(user=instance)
        
        post_save.connect(create_user_profile, sender=User)

admin.py 
class UserProfileInline(admin.StackedInline):
    fk_name = 'user'
    model = UserProfile
#    can_delete = False
#    verbose_name_plural = 'profile'


# Define a new User admin
class UserAdmin(UserAdmin):
    inlines = (UserProfileInline, )


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)


settings中
AUTH_PROFILE_MODULE = 'accounts.UserProfile'

最后 开启mezz的accounts功能  即可完成。


上面看起来简单  实际我却配置了一天才弄出来              不容易啊 
 
不懂可以加入 mezzanine讨论群 和大家一起讨论  153735756

 类似资料: