Django: Access Admin User in Python Shell

大城市里の小女人 提交于 2019-12-10 13:06:12

问题


I am using Django Userena, but when trying to login to the django admin screen userena is creating a fuss: Profile matching query does not exist.

How can I create a profile for the admin user using the shell? Here is my Profile model, but I don't know how to access the key for the admin user to create a Profile object for it:

class Profile(UserenaBaseProfile, FacebookProfileModel):
    user = models.OneToOneField(User,
                                unique=True,
                                verbose_name=('user'),
                                related_name='my_profile')
    website = models.URLField(null=True, blank=True)

I know this is probably pretty simple, but google has failed me so far... Thanks for your ideas!

PS. I used to be able to login to my admin screen without issue, but something has changed now and I am getting the Profile matching query does not exist error (I didn't change the code, either).. Any ideas why I can't login now are also appreciated. Thanks!


回答1:


You can do something like this:

$ ./manage.py shell
> from django.contrib.auth.models import User
> from <profile_package>.models import Profile
> user = User.objects.get(username='<admin_user_name>')
> profile = Profile(user=user)
> profile.save()


来源:https://stackoverflow.com/questions/17620783/django-access-admin-user-in-python-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!