我的一些错误与我非常有限的python知识有关,但我现在已经搜索了半天。
class AssignmentForm(forms.ModelForm):
def __init__(self, *args, **kwargs, m_id):
super(AssignmentForm, self).__init__(*args, **kwargs)
# Making name required
self.fields['title'].required = True
self.fields['title'].help_text = "Title Required"
self.fields['description'].required = True
self.fields['description'].help_text= "Description Optional"
self.fields['module_id'].required = False
self.fields['module_id'] = m_id
class Meta:
# Provide an association between the ModelForm and a model
model = Assignment
fields = ('title', 'description', 'module_id')
这是我的观点
def add_assignment(request, m_id):
template = loader.get_template('add_assignment.html')
if request.method == 'POST':
form = AssignmentForm(request.POST, m_id)
if form.is_valid():
form.save(commit=True)
return module(request, m_id)
else:
print form.errors
else:
form = AssignmentForm()
# Bad form (or form details), no form supplied...
# Render the form with error messages (if any).
context = RequestContext(request,
{
'form':form,
})
return HttpResponse(template.render(context))
这是我的网址映射
url(r'^courses/(?P<m_id>\d+)/new/$', add_assignment, name='add_assignment'),
我目前收到错误,因为我不能将值传递给init但是我不知道如何获得&#39; module_id&#39;英寸
再次感谢,我意识到我可能正在构建整个事情。