loadAdminUser.py 709 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
16
17
18
19
20
        """
        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(
                username="admin",
                email='null@null.fr',
                password='admin',
            )
            self.admin = User.objects.filter(username="admin")[0]
Florent Chehab's avatar
Florent Chehab committed
21
22
23

    def get(self):
        return self.admin