简体   繁体   中英

How do I add custom fields to a User when using django-social-auth

I need to add a BooleanField and a ManyToManyField to my users. I'm using django-social-auth. It seems I could use 'CustomUser'. I guess that's what it's for, but how do I take it into use?

I would need to know:

  1. where to define these new fields
  2. How to add them to the new user when the user is created (ie logs in)
  3. How the query the fields afterwards (ie User.myBooleanField?)

Thanks!

Create a model called CustomUser or UserProfile, whatever you want, with these fields.

In settings.py add a setting AUTH_PROFILE_MODULE = "account.UserProfile", with what you named your model.

In the signals for social_auth, make sure the user has a profile, and if not create it for them when the user is created.

Now anywhere in the site you can call user.get_profile() and you'll have access to these fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM