For the django admin, how do I add a field to the User model and have it editable in the admin?

后端 未结 5 1282
闹比i
闹比i 2021-02-04 10:42

I\'m trying to understand the django admin better and at the same time, I\'m trying to add one more field to the current user admin. In models.py I\'ve done

Use         


        
5条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 10:59

    Despite your DB look up concerns for having a UserProfile, that is really the way you should go for this problem. There are two main reasons for this:

    1. The User Model is pretty tightly coupled to Django's authentication system and to many other plugins. Monkey patching it isn't a good idea.

    2. Django has built-in support for creating User Profiles and many extensions know how to play nicely with these. By using User Profiles (see http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users for the main discussion on this) you can benefit from that.

    If you're looking to add functionality to the Admin interface for users, then this note may be helpful:

    http://www.thenestedfloat.com/articles/displaying-custom-user-profile-fields-in-djangos-admin/index.html

    Regards,

    Ian

提交回复
热议问题