RelatedObjectDoesNotExist (Django)

0

I have the error RelatedObjectDoesNotExist, follow the Traceback. Traceback:

File "/usr/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner   34. response = get_response (request)

File "/usr/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response   126. response = self.process_exception_by_middleware (e, request)

File "/usr/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response   124. response = wrapped_callback (request, * callback_args, ** callback_kwargs)

File "/usr/lib/python3.7/site-packages/django/views/generic/base.py" in view   68. return self.dispatch (request, * args, ** kwargs)

File "/usr/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch   88. return handler (request, * args, ** kwargs)

File "/usr/lib/python3.7/site-packages/django/views/generic/list.py" in get   142. self.object_list = self.get_queryset ()

File "/home/sh1r0y4sh4/www/sigest1.1/users/views/student.py" in get_queryset   34. student = self.request.user.student

File "/usr/lib/python3.7/site-packages/django/utils/functional.py" in inner   214. return func (self._wrapped, * args)

File "/usr/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py" in get   414. self.related.get_accessor_name ()

Exception Type: RelatedObjectDoesNotExist at / users / list / Exception Value: User has no student.

models.py

   username = models.CharField(_('usuario'), max_length=15, unique=True, help_text=_('Requer 15 caracteres ou menos'))
password = models.CharField(_('senha'), max_length=15, help_text=('Digite uma senha com 15 caracteres ou menos'))
email = models.EmailField(_('email'), max_length=255, unique=True)

is_superuser = models.BooleanField(_('Status de Superusuário'), default=False,
                                   help_text=_('Designado para Superusuários '))
is_staff = models.BooleanField(_('Status de staff'), default=False,
                               help_text=_('Designado para usuarios da equipe'))
is_active = models.BooleanField(_('active'), default=False,
                                help_text=_('Designado para usuários ativos. \ Em vez de deletar, desative o mesmo.'))

is_student = models.BooleanField (_('Aluno'), default=False,
                                  help_text=_('Designado para usuarios do tipo Aluno'))

is_advisor = models.BooleanField(_('Orientador'), default=False,
                                  help_text=_('Designado para usuarios do tipo Orientador'))

is_supervisor = models.BooleanField(_('Supervisor'), default=False,
                                  help_text=_('Designado para usuarios do tipo Supervisor'))

date_joined = models.DateTimeField(_('data de ingresso'), default=timezone.now)

is_trusty = models.BooleanField(_('Email confirmado'), default=False,
                                help_text=_('Usuários com contas confirmadas.'))

matricula = models.IntegerField()

objects = UserManager()

USERNAME_FIELD = 'username'

REQUIRED_FIELDS = ['email', 'matricula', 'is_staff', 'is_superuser']

class Meta:
    verbose_name = _('usuario')
    verbose_name_plural = _('usuarios')

class Student(models.Model):
    user = models.OneToOneField(Usuario, on_delete=models.CASCADE, primary_key=True)

class Advisor(models.Model):
    user = models.OneToOneField(Usuario, on_delete=models.CASCADE, primary_key=True)

student.py

class StudentSignupView(CreateView):
model = Usuario
form_class= StudentSignupForm
template_name = 'registration/signup_form_student.html'

def get_context_data(self, **kwargs):
    kwargs['user_type'] = 'student'
    return super().get_context_data(**kwargs)


def form_valid(self, form):
    user = form.save()
    login(self.request, user)
    return redirect('students:student_list')

class StudentListView(ListView):
    model = Student
    ordering = ('name')
    context_object_name = 'students'
    template_name = 'students/students_list.html'

    def get_queryset(self):

            student = self.request.user.student
        queryset = Student.objects.filter(subject__in=student)
        return queryset

Does anyone know how to help?

    
asked by anonymous 22.11.2018 / 16:27

0 answers