profcturner / WAM

Workload Allocation Modeller and Assessment Approval System
GNU Affero General Public License v3.0
4 stars 0 forks source link

Created Superusers at the command line have no matching Staff object #45

Closed profcturner closed 2 years ago

profcturner commented 3 years ago

Two people have tried to install WAM and run into this issue. The code now will cause exceptions if a User has no matching Staff object, and yet the createsuperuser does not create the Staff.

Hmm, it’s actually probably a flaw in that your user object has no matching staff user, and something I will definitely need to resolve. We must file an issue on that.

In the mean time, try something like the following will work around this.

python3 manage.py shell

Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)

from loads.models import Staff from django.contrib.auth.models import User users = User.objects.all() users[0]

root_user = users[0] staff = Staff.objects.create(user=root_user, title="Mr", staff_number="whatever")
profcturner commented 2 years ago

The decorator @staff_only has been altered to create a Staff object for superusers with no matching Staff object, this should allow created superusers to log in without any further drama.