2010-01-20 85 views
1

我正在寫一個Django管理員操作來羣發電子郵件聯繫人。該動作被定義如下:在Django的管理界面中發佈表格

def email_selected(self,request,queryset): 
    rep_list = [] 
    for each in queryset: 

     reps = CorporatePerson.objects.filter(company_id = Company.objects.get(name=each.name)) 

     contact_reps = reps.filter(is_contact=True) 
     for rep in contact_reps: 
      rep_list.append(rep) 

    return email_form(request,queryset,rep_list) 

email_form存在作爲視圖和填充的模板,此代碼:

def email_form(request,queryset,rep_list): 
    if request.method == 'POST': 
     form = EmailForm(request.POST) 
     if form.is_valid(): 
      cd = form.cleaned_data 
      send_mail(
       cd['subject'], 
       cd['message'], 
       cd.get('email','[email protected]'),['[email protected]'], 
      ) 
      return HttpResponseRedirect('thanks') 
     else: 
      form = EmailForm() 
     return render_to_response('corpware/admin/email-form.html',{'form':form,}) 

和存在於模板如下:

<body> 
    <form action="/process_mail/" method="post"> 
     <table> 
      {{ form.as_table }} 
     </table> 
     <input type = "submit" value = "Submit"> 
    </form> 
</body> 

/process_mail /被硬鏈接到urls.py中的另一個視圖 - 這是一個問題。我真的很喜歡它,所以我不必使用<form action="/process_mail/" method="post">,但不幸的是,我似乎無法將用戶輸入發佈到視圖處理程序,而無需管理界面爲該模型重新加載它的位置(當我點擊提交按鈕,出現管理界面,這是我不想要的。)

有沒有一種方法可以使表單POST自身(<form action="" method="post">),以便我可以處理在email_form中接收到的輸入?嘗試處理帶有無關URL和不需要的函數的輸入會困擾我,因爲我對URL進行了硬編碼以處理代碼。

回答