0
有人可以帮我解决下面的错误并解释这个问题吗?所有我想要做填充查询集一组,但在提交我碰到下面的错误形式...表单错误int()参数必须是字符串或数字,而不是'QueryDict'
* 类型错误在/ SMS/addbatch int()函数的参数必须是字符串或数字,而不是 '的QueryDict' *
views.py
def add_batch(request):
# If we had a POST then get the request post values.
if request.method == 'POST':
form = BatchForm(request.POST)
# Check we have valid data before saving trying to save.
if form.is_valid():
# Clean all data and add to var data.
data = form.cleaned_data
groups = data['group'].split(",")
for item in groups:
batch = Batch(content=data['message'],
group=Group.objects.get(pk=item),
user=request.user
)
form.py
class BatchForm(forms.ModelForm):
class Meta:
model = Batch
def __init__(self, user=None, *args, **kwargs):
super(BatchForm, self).__init__(*args,**kwargs)
if user is not None:
form_choices = Batch.objects.for_user_pending(user)
else:
form_choices = Batch.objects.all()
self.fields['group'] = forms.ModelMultipleChoiceField(
queryset=form_choices
)
models.py
class BatchManager(models.Manager):
def for_user_pending(self, user):
return self.get_query_set().filter(user=user, status="Pending")
感谢,这是有道理的。 – MarkO 2013-03-22 11:09:14