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