问题
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