Jatin Bhola Jatin Bhola - 3 months ago 12
Python Question

MongoDBForm error "ValueError:A document class must be provided"

Hi i am creating a simple Sign Up form with django framework and mongodb. Following is my view:

class SignUpView(FormView):
template_name='MnCApp/signup.html'
form_class=EmployeeForm()
succes_url='/success/'


Following is my model:

class Employee(Document):
designation=StringField()
department=StringField()
emp_name=StringField(max_length=50)
password=StringField(max_length=10)


Following is my
forms.py


class EmployeeForm(DocumentForm):
class meta:
desigs=(
('D','Director'),
('GM','General Manager'),
('AM','Assistant Manager'),
('A','Associates')
)
deptts=(
('HR','Human Resources'),
('IT','IT Support'),
('TT','Technical Team'),
('SM','Sales and Marketting'),
('SS','Support Staff')
)
document=Employee
fields='__all__'
widgets={
'designation':Select(choices=desigs),
'department':Select(choices=deptts)
}


Following is the traceback ValueError recieved on loading SignUpview
Traceback:


File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\exception.py" in inner
39. response = get_response(request)

File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Program Files\Python35\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "C:\Program Files\Python35\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)

File "C:\Program Files\Python35\lib\site-packages\django\views\generic\edit.py" in get
174. return self.render_to_response(self.get_context_data())

File "C:\Program Files\Python35\lib\site-packages\django\views\generic\edit.py" in get_context_data
93. kwargs['form'] = self.get_form()

File "C:\Program Files\Python35\lib\site-packages\django\views\generic\edit.py" in get_form
45. return form_class(**self.get_form_kwargs())

File "C:\Program Files\Python35\lib\site-packages\mongodbforms\documents.py" in init
353. raise ValueError('A document class must be provided.')

Exception Type: ValueError at /signup/
Exception Value: A document class must be provided.


I am not able to find root of this problem. I am new to django and this is my first project. Also is their anyother way for creating model forms for mongo documents??

Answer

I suspect that your inner class should be called Meta, not meta.

Comments