Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Access Admin User in Python Shell

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!

like image 836
Nick B Avatar asked Jul 12 '13 17:07

Nick B


1 Answers

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()
like image 92
karthikr Avatar answered Oct 18 '22 20:10

karthikr