good day guys

33 views
Skip to first unread message

Tosin Ayoola

unread,
Dec 4, 2019, 7:10:52 PM12/4/19
to django...@googlegroups.com
halo guys, i'm working on a school management system that has multi user (student and staffs), i've created the model, views and form but i'm getting this error which i'm not familiar with. i'll b glad if anyone can help out
below is the view, model, form and the err

#forms
class StudentSignupForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = UserRole
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_student = True
if commit:
user.save()
return user

class StaffSignupForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = UserRole
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_staff = True
if commit:
user.save()
return user


#views
class StudentSignUp(CreateView):
model = UserRole
form_class = StudentSignupForm
template_name = 'register/signup.html'

def get_context_data(self, **kwargs):
kwargs['user_type'] = 'student'
return super().get_context_data(**kwargs)
def student_valid_form(self, student_form):
user = student_form.save()
login(self.request, user)
return redirect('students:student_index')

class StaffSignup(CreateView):
model = UserRole
form_class = StaffSignupForm
template_name = 'register/signup.html'

def get_context_data(self, **kwargs):
kwargs['user_type'] = 'staff'
return super().get_context_data(**kwargs)
def staff_valid_form(self, staff_form):
user = staff_form.save()
login(self.request, user)
return redirect('staff:staff_index')




#models

class UserRole(AbstractUser):
is_student = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
Screenshot from 2019-12-05 01-04-09.png

jose angel encinas ramos

unread,
Dec 4, 2019, 7:49:23 PM12/4/19
to django...@googlegroups.com
Buenas tardes, ya creaste un super usuario en django?,
creo que te hace falta correr python manage.py makemigrations
despues python manage.py migrate

intenta eso

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn71OveFEozZ7J7b%3DGMBgtB7LvurcoOgbDEiTQXX%3DO%3D9zTw%40mail.gmail.com.


--
José Ángel Encinas
Ing. Tecnologias de la informacion


Cel:  6622267620 

  
                   Never give up...

Tosin Ayoola

unread,
Dec 4, 2019, 7:58:38 PM12/4/19
to django...@googlegroups.com
buenos días, gracias, sí, tengo un súper usuario creado, pero no puedo ejecutar ningún comando que use manage.py
Gracias

Jorge Gimeno

unread,
Dec 5, 2019, 10:01:55 PM12/5/19
to django...@googlegroups.com
By chance did you set AUTH_USER_MODEL in settings.py?  That's a requirement if you're using a custom user model (I guessed that because your UserRole inherits from AbstractUser). There's a good tutorial on writing a custom user model here:  https://wsvincent.com/django-custom-user-model-tutorial/

-Jorge

Tosin Ayoola

unread,
Dec 6, 2019, 1:53:02 AM12/6/19
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages