title: 'super' object has no attribute 'form_valid' (Django)
body: <p>I think the reason that I got this error maybe because I didn't use <code>FormMixin</code> and form_class in the detailView. I have tried it but my form will not run without <code>current_class_pk</code> (I added it inside my AttendanceForm using <code>kwargs.pop</code>) so I have to use <code>get_context_data</code> to pass the pk of detailview to the form.</p>
  <p>How can I fix this? or Are there anyway other ways to pass detailview pk to the form_class?</p>
  <p>view.py</p>
  <pre><code>class Class_detailView(LoginRequiredMixin, DetailView):
      login_url = '/'
      model = Class
      template_name = &quot;attendance/content/teacher/class_detail.html&quot;
  
      def get_context_data(self, **kwargs):
          class_pk = self.object.pk 
          print(class_pk)
          context = super(Class_detailView, self).get_context_data(**kwargs)
          context['attendance_form'] = AttendanceForm(current_class_pk=class_pk) # pass data to form via kwargs 
          return context
  
      def get_success_url(self):
          return reverse('class_detail', kwargs={'pk': self.object.pk})
  
      def post(self, request, *args, **kwargs):
          self.object = self.get_object()
          if request.method == &quot;POST&quot;:
              attendance_form = AttendanceForm(request.POST, current_class_pk=self.kwargs.get('pk'))
              if attendance_form.is_valid():
                  return self.form_valid(attendance_form)
  
      def form_valid(self, form):
          form.instance.teacher = self.request.user
          form.instance.attendance_class = self.object
          form.save()
          return super(Class_detailView, self).form_valid(form)
  </code></pre>
  <p>forms.py</p>
  <pre><code>class AttendanceForm(forms.ModelForm):
      class Meta:
          model = Attendance
          fields = ['student',]
  
      def __init__(self, *args, **kwargs):
          current_class_pk = kwargs.pop('current_class_pk')
          super(AttendanceForm, self).__init__(*args, **kwargs)
          current_student = Class.objects.get(id=current_class_pk)
          self.fields['student'].queryset = current_student.student
  </code></pre>
  <p>error i got</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/core/handlers/exception.py&quot;, line 47, in inner
      response = get_response(request)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/core/handlers/base.py&quot;, line 179, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/views/generic/base.py&quot;, line 73, in view
      return self.dispatch(request, *args, **kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/utils/decorators.py&quot;, line 43, in _wrapper
      return bound_method(*args, **kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/contrib/auth/decorators.py&quot;, line 21, in _wrapped_view
      return view_func(request, *args, **kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/contrib/auth/mixins.py&quot;, line 52, in dispatch
      return super().dispatch(request, *args, **kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/env/lib/python3.8/site-packages/django/views/generic/base.py&quot;, line 101, in dispatch
      return handler(request, *args, **kwargs)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/annexar-attendance/attendance/views.py&quot;, line 199, in post
      return self.form_valid(attendance_form)
    File &quot;/Users/muongkimhong/Developments/annexar-attendance/annexar-attendance/attendance/views.py&quot;, line 205, in form_valid
      return super(Class_detailView, self).form_valid(form)
  AttributeError: 'super' object has no attribute 'form_valid'
  </code></pre>