1class FolderCreate(CreateView):
2 template_name = 'Form/folder_create.html'
3 form_class = FolderForm
4
5 def get_form_kwargs(self):
6 kwargs = super(FolderCreate, self).get_form_kwargs()
7 kwargs['user'] = self.request.user
8 return kwargs
1class FolderForm(forms.ModelForm):
2 class Meta:
3 model = Folder
4 fields = ['name', 'parent']
5
6 def __init__(self, *args, **kwargs):
7 user = kwargs.pop('user')
8 super(FolderForm, self).__init__(*args, **kwargs)
9 self.fields['parent'].queryset = Folder.objects.filter(user=user)