Answer the question
In order to leave comments, you need to log in
'NoneType' object has no attribute '__dict__'?
views.py:
class CreateStudent( CreateView):
form_class = FormAddStudent
template_name = 'app/create_student.html'
success_url = 'index'
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 questionAsk a Question
731 491 924 answers to any question