I use the django-social-auth
plug-in in Django.
I would like to join Django's admin as a user generated after I authenticate with Facebook.
First, create this user on models.py and
To force is_staff to be true, we did the following:
class CustomUser (User):
class Meta:
verbose_name = u 'Custom User'
verbose_name_plural= verbose_name
def__init__(self, *args, **kwargs):
super(User,self).__init__(*args,**kwargs)
# self._meta.get_field('is_staff') .default=True #Tried but failed
super(User,self)._meta.get_field('is_staff') .default=True
# CustomUser._meta.get_field('is_staff').default=True
SOCIAL_AUTH_USER_MODEL='my_app.CustomUser'
It was done as shown in .
I've tried a lot of comments.
However, I was unable to log in as a Facebook user.
Next, I found a similar article.
https://djangosnippets.org/snippets/2856/
But I couldn't.
on settings.py
USE_SOCIAL_AUTH_AS_ADMIN_LOGIN
, but SOCIAL_AUTH_USE_AS_ADMIN_LOGIN
on admin.py
I thought it was strange, so I changed it to the same variable, but I still couldn't.
If there is a solution, please let me know.
python oauth social-framework facebook-api django
However, I was unable to log in as a Facebook user.
I think this depends on the user being created on the Django side.
So,
Trying to force is_staff to be true
I will only answer this part.The following are the CUTOMUser improvement codes:
class CustomUser (User):
class Meta:
verbose_name = u 'Custom User'
verbose_name_plural= verbose_name
def__init__(self, *args, **kwargs):
super(User,self).__init__(*args,**kwargs)
self.is_staff=True
Since is_staff
is already false
in the first process of _init__()
, we have unconditionally set it to True
in the following process:
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
597 GDB gets version error when attempting to debug with the Presense SDK (IDE)
884 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
567 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.