0

モデルではこれがあります:

   section = models.ForeignKey("Sections", verbose_name='Раздел')     

私の見解:

def announs_add(request):
  if request.method == 'POST':
        form = add_form(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            section_obj = get_object_or_404(Sections, id=cd['section']),
            announ = Announs(section=section_obj)
            announ.save()
            form = add_form()
  else:
       form = add_form()
  return render_to_response('announs/announs_add.html',
  {
    'form':form,
  }, context_instance = RequestContext(request), )

たとえば何かを追加しようとすると、私はこれを持っています:

Cannot assign "u'\u041d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u0432\u043e\u0435\u0439 \u043f\u043e\u043c\u043e\u0449\u0438'": "Announs.section" must be a "Sections" instance.

これを修正するのを手伝ってください。

4

1 に答える 1

0

この余分なコンマ:

                                                         # v-- this one
section_obj = get_object_or_404(Sections, id=cd['section']), 

タプル(セクションを含む1タプル)を作成します。カンマを削除します。

section_obj = get_object_or_404(Sections, id=cd['section'])
于 2013-03-21T14:32:53.683 に答える