loadAdminUser.py 676 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
4
5
from django.contrib.auth.models import User


class LoadAdminUser(object):
    def __init__(self):
Florent Chehab's avatar
Florent Chehab committed
6
7
8
9
10
11
12
13
14
15
        """
        Creating admin user by creating a user and setting is_staff is True
        didn't enable access to the admin system for an unkown reason.
        Need to use create_superuser.
        """
        user = User.objects.filter(username="admin")
        if len(user) > 0:
            self.admin = user[0]
        else:
            User.objects.create_superuser(
16
                username="admin", email="null@null.fr", password="admin"
Florent Chehab's avatar
Florent Chehab committed
17
18
            )
            self.admin = User.objects.filter(username="admin")[0]
Florent Chehab's avatar
Florent Chehab committed
19
20
21

    def get(self):
        return self.admin