T
T
tarp202021-06-24 13:15:27
Django
tarp20, 2021-06-24 13:15:27

'NoneType' object has no attribute '__dict__'?

views.py:

class CreateStudent( CreateView):
    form_class = FormAddStudent
    template_name = 'app/create_student.html'
    success_url = 'index'


forms.py:

class FormAddStudent(forms.ModelForm):
    class Meta:
        model = Student
        fields = ('name',)

    courses = forms.ModelMultipleChoiceField(queryset=Course.objects.all(), initial=Course.objects.order_by('id').first())

    def save(self, *args, **kwargs):
        obj = super().save(*args, **kwargs)
        obj.course_set.set(self.cleaned_data['courses']
)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question